[Resolved] see the reading time in a post page home

Home Forums Support see the reading time in a post page home

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1060767
    alexis

    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?

    Alexis
    agency K-LYA

    #1061172
    Tom
    Lead Developer
    Lead Developer

    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 🙂

    #1061419
    alexis

    Perfect! thank you very much, it works.

    Alexis
    agency K-LYA

    #1062098
    Tom
    Lead Developer
    Lead Developer
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.