- This topic has 22 replies, 6 voices, and was last updated 1 year, 5 months ago by David.
-
AuthorPosts
-
September 28, 2022 at 6:32 am #2356337alexis
Hello I added this code in php following this post : https://generatepress.com/forums/topic/reading-time-code-to-add-to-entry-meta/
function tu_estimated_reading_time() { $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 = ceil( $word_count / $wpm ); return $time . ' min'; } add_shortcode('reading-time', 'tu_estimated_reading_time');
Then I added a short code with this code
<?php echo '<div class="read-time">.'<span>'Temps de lecture </span> '( '[reading-time]' ) . '</div>'; ?>
But it does not work when I remove the quotes I lose the reading time (4min => 1 min) How to do please ?
September 28, 2022 at 6:41 am #2356342WilliamI just came to the the forum to add my own issue π
Just with this, Yoast has this automatically – would recommend exploring it!
September 28, 2022 at 2:54 pm #2356903YingStaffCustomer SupportHi Alexis,
Where and how did you add this?
<?php echo '<div class="read-time">.'<span>'Temps de lecture </span> '( '[reading-time]' ) . '</div>'; ?>
Hi Will,
Thanks for the information π I didn’t know that!
September 29, 2022 at 12:01 am #2357261alexisI added this in the block gutemberg shortcode
September 29, 2022 at 12:08 am #2357269Fernando Customer SupportHi Alexis,
If it’s a Shortcode Block, the shortcode should just be
[reading-time]
Can you take a screenshot of how you added it?
September 29, 2022 at 12:13 am #2357277alexisI add this <?php echo do_shortcode(“[reading-time]”); ?> but it does not work
September 29, 2022 at 12:44 am #2357307Fernando Customer SupportCan you try adding just this:
[reading-time]
in a Shortcode Block?September 29, 2022 at 12:48 am #2357309alexisOk it’s ok thanks but how to add html markup + text reading time
September 29, 2022 at 1:22 am #2357347Fernando Customer SupportAlter the code you have to this:
function tu_estimated_reading_time() { $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 = ceil( $word_count / $wpm ); return '<div class="read-time"><span>Temps de lecture </span>' . $time . ' min</div>'; } add_shortcode('reading-time', 'tu_estimated_reading_time');
September 29, 2022 at 1:36 am #2357367alexisThanks perfect, you are the best π
September 30, 2022 at 1:19 am #2358494Fernando Customer SupportYou’re welcome Alexis! π
September 30, 2022 at 1:27 am #2358504alexisSorry another question I want to display the reading time in my pages displayed at the bottom. Except that I need to retrieve the time according to source. Is it possible to do that? if yes how?
You can see the example at the bottom of my page: “How does a search engine work?”
September 30, 2022 at 5:16 am #2358697Fernando Customer SupportFor reference, can you re-share the link to the site in question?
September 30, 2022 at 5:19 am #2358703alexisI add in private
October 2, 2022 at 5:29 pm #2360932Fernando Customer SupportWill you be using a Query Loop Block or will you be adding the “For Further” section posts manually as you are now?
-
AuthorPosts
- You must be logged in to reply to this topic.