Are you a GenerateCustomer?

Do you have an active GP Premium or GenerateBlocks Pro license key?

Create a GenerateSupport account for GeneratePress and GenerateBlocks support in one dedicated place.

Create an account
Already have a GenerateSupport account? Login

Just browsing?

Feel free to browse the forums. Support for our free versions is provided on WordPress.org (GeneratePress, GenerateBlocks).

Want to become a premium user? Learn more below.

Add “estimated read” time on post and archive loop

  • Hello, yesterday i just tried from a 4-5 solutions of the diferent topics of this support, but with no results for me 🙁

    I want to add a “estimated time read” next to dynamic fields of the author and date, on my blog post (and loop archive too).

    capture: https://i.postimg.cc/RhykKzWM/post-reading-time.png

    I have added the David´s code on child functions.php: https://generatepress.com/forums/topic/add-reading-time-on-posts-after-the-author-name/#post-2431086

    I have added a headline block with text time and class “reading-time” but there no result (please, see capture), i sure i´m missing anything to make / add.

    Can you help me, please?

  • Hi there,

    Could you provide temporary admin login access so we can take a closer look at the backend settings?

  • Hello, yes of course, in private reply is the acces.

    The element that i use in post hero is: Header (entradas blog)

    Thank you 🙂

  • The credentials don’t appear to be working. Could you please double-check them?

  • Sorry, my mistake, just updated the pass. 🙂

  • Hi there,

    try this function:

    
    function modify_reading_time_block_content( $block_content, $block ) {
        if ( isset( $block['attrs']['className'] ) && strpos( $block['attrs']['className'], 'reading-time' ) !== false ) {
            global $post;
            if ( is_single() && $post ) {
                $words_per_minute = 200;
                $display_format = 'full'; // Options: 'minutes' or 'full'
                $reading_time = str_word_count( wp_strip_all_tags( $post->post_content ) ) / $words_per_minute;
    
                $minutes = floor( $reading_time );
                $seconds = round( ( $reading_time - $minutes ) * 60 );
                
                $time_display = $minutes > 0 ? "{$minutes} min" : '';
                $time_display .= $seconds > 0 ? " {$seconds} sec" : '';
                
                $block_content = sprintf( '<div class="reading-time">Estimated Reading Time: %s</div>', trim( $time_display ) );
            }
        }
        return $block_content;
    }
    add_filter( 'render_block', 'modify_reading_time_block_content', 10, 2 );
    

    Then select the block you want to return the time on and give it an Advanced > Additional CSS Class of: reading-time

  • Hello David, thank you! i already added this function on the child theme (functions.php) and the reading-time class (capture 1) but it do not shows the reading time on my web (capture 2)

    1. https://postimg.cc/mzSNfqtP
    2. https://postimg.cc/1f86J4cn

    Whaht i am doing bad?

    Thank you 🙂

  • Where did you add the PHP Snippet to your site ?

  • I use child theme, i added this on functions.php

  • I looked in the child theme functions.php and I do not see the code.

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.