-
armandas
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?
-
armandas
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?
-
armandas
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
-
armandas
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/1f86J4cnWhaht i am doing bad?
Thank you 🙂
-
Where did you add the PHP Snippet to your site ?
-
armandas
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.
- You must be logged in to reply to this topic.