-
Pedro Reyes
Hello,
Is there any way to place the reading time of the blog post in the generablocks query loops, and inside the blog post as such?
-
Hi there,
Are you using a plugin to add the reading time? Does the plugin offer a block or a shortcode?
-
Pedro Reyes
Hello Ying,
I am not using any plugin that has that functionality.
-
Fernando
Hi there,
I see. Could you share the link to where we can find your Query Loop?
-
Pedro Reyes
Hello Fernando,
The site is this: https://bkdev.site/
I have been searching and found a snippet to add something similar with Rank Math.
However it only works within the blog post, and not in the query loops.
This is the script:
add_shortcode( 'rm_reading_time', 'define_custom_shortcode_function' ); function define_custom_shortcode_function() { global $post; $content = wp_strip_all_tags( $post->post_content ); $words_per_minute = 250; $time = ceil(str_word_count($content)/$words_per_minute); return strval($time); } -
Fernando
Add a GB Headline Block for the Reading time in your Query Loop.
Then, type the shortcode
[rm_reading_time]inside this Headline, add a CSS class to the headline, eg.get-reading-time. Adding Custom Classes: https://wordpress.com/support/wordpress-editor/adding-additional-css-classes-to-blocks/Add this PHP code to render the headline:
add_filter( 'render_block_generateblocks/headline', function( $block_content, $block ) { if ( !is_admin() && ! empty( $block['attrs']['className'] ) && strpos( $block['attrs']['className'], 'get-reading-time' ) !== false ) { $post_id = get_the_ID(); $block_content = do_shortcode('[rm_reading_time]'); } return $block_content; }, 10, 2 );Adding PHP: https://docs.generatepress.com/article/adding-php/#code-snippets
- You must be logged in to reply to this topic.