Site logo

Archived topic

see the reading time in a post page home

3 replies · Started by alexis on November 12, 2019

Viewing posts 1–4 of 4

I use this code :


function tu_estimated_reading_time() {
    $post = get_post();
    $content = $post->post_content;
    $wpm = 300; // 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 );
    var_dump( $time );

    return $time;
}

add_filter( 'generate_post_author_output', function( $output ) {
    $output .= '<div class="read-time">Reading time: ' . tu_estimated_reading_time() . '</div>';

    return $output;
} );

but I want to have the same display for posts displayed on pages (home for example). I use Wp show Posts. How can I do that?

Hi there,

You could do something really similar:

add_filter( 'wpsp_date_output', function( $output ) {
    $output .= '<div class="read-time">Reading time: ' . tu_estimated_reading_time() . '</div>';

    return $output;
} );

Let me know :)

Perfect! thank you very much, it works.

You're welcome :)

This archived topic is closed to new replies.