Calling an attribute from a plugin shortcode

The shortcode uses ‘postfix’ and ‘postfix_singular’, which can be used in your code in a few ways. You can pass them directly in your do_shortcode() call: echo do_shortcode('[rt_reading_time postfix="minutes" postfix_singular="minute"]'), but that doesn’t help when you want to use translations. For that, you can use sprintf() to create a string that gets passed to do_shortcode() as a parameter.

Example:

$shortcode_call = sprintf(
    '[rt_reading_time postfix="%1$s" postfix_singular="%2$s"]',
    esc_html_x( 'minutes', 'minutes plural', 'plugin-slug' ),
    esc_html_x( 'minute', 'minutes single', 'plugin-slug' )
);

echo do_shortcode( $shortcode_call );