Viewing 4 replies - 1 through 4 (of 4 total)
  • I am looking for something like this as well.

    I’m using Essential Grid, and would love for the posts to show the Reading Time.

    Is there any shortcode to show reading time by passing post id?

    Plugin Author Jason Yingling

    (@yingling017)

    You could use the following code to get the reading time calculation by post ID.

    `
    global $readingTimeWP;
    $reading_time = $readingTimeWP->rt_calculate_reading_time(1, get_option(‘rt_reading_time_options’) );
    `

    global $readingTimeWP; is accessing the readingTimeWP class.

    Then on the next line we’re calling the rt_calculate_reading_time() function from the class and setting it’s value to $reading_time. This function only outputs the final time calculation though. It doesn’t include the labels. So you’d have to add those in yourself when you output the $reading_time variable.

    Hopefully that gets you started!

    Thread Starter ego55

    (@ego55)

    Thanks, it works perfectly!

    Thank you, Jason.

    I used this code in functions.php

    function readtimefunc( $atts ) {
    	global $readingTimeWP;
    $reading_time = $readingTimeWP->rt_calculate_reading_time($atts['foo'], get_option('rt_reading_time_options') );
    	return $reading_time;
    }
    add_shortcode( 'readtimeshort', 'readtimefunc' );

    Then I added this shortcode to Essential Grid

    [readtimeshort foo='%post_id%']

    It works, except it displays just a number, like “1”, rather than the value, “READING TIME: 1 MINUTE”

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Get reading time by id’ is closed to new replies.