Site logo

Archived topic

Estimated Read Time in Author box

3 replies · Started by J. on January 18, 2022

Viewing posts 1–4 of 4

Hi there,

I've tried to add a function to add the estimated read time, but I can't get it to work. I've consulted these topics already:

I'm using the template 'Volume', which works with Elements.

Can you guide me through?

Thanks!

Hi there,

you can use this PHP Snippet:

function tu_estimated_reading_time() {
    $post = get_post();
    $content = $post->post_content;
    $wpm = 250; // How many words per minute.

    $clean_content = strip_shortcodes( $content );
    $clean_content = strip_tags( $clean_content );
    $word_count = str_word_count( $clean_content );
    $time = ceil( $word_count / $wpm );

    return $time . ' min';
}
add_shortcode('reading-time', 'tu_estimated_reading_time');

This will create the following shortcode that you can add to your element:

[reading-time]

Clear, thank you!

Glad to be of help

This archived topic is closed to new replies.