JJCoding
Forum Replies Created
Viewing 2 replies - 1 through 2 (of 2 total)
-
Forum: Plugins
In reply to: [Reading Time WP] Gutenberg Query LoopFixed this by creating my own filter instead of using a plug-in.
add_filter( 'render_block', function( $block_content, $block ) { if (!is_admin() && ! empty( $block['attrs']['className'] ) && 'reading-time' === $block['attrs']['className']){ $post = get_post(); $content = $post->post_content; $wpm = 250; // How many words per minute. $clean_content = strip_shortcodes( $content ); $clean_content = strip_tags( $clean_content ); $word_count = str_word_count( $clean_content ); $time = $word_count / $wpm; if($time > 1) { $suffix = 'minutes'; } else { $suffix = 'minute'; } if($time < 1) { $time = '< 1'; } else { $time = ceil( $word_count / $wpm ); } $block_content = '<span class="read-time">Reading time: ' . $time .' '. $suffix . '</span>'; } return $block_content; }, 10, 2 );Credit to: https://generatepress.com/forums/topic/add-reading-time-on-posts-after-the-author-name/
- This reply was modified 3 years, 1 month ago by JJCoding.
Hi, ticket has been made!
Viewing 2 replies - 1 through 2 (of 2 total)