- This topic has 22 replies, 6 voices, and was last updated 3 months, 1 week ago by
David.
-
AuthorPosts
-
October 2, 2022 at 10:53 pm #2361076
alexis
I use dynamic data on the title or image element. These are pages that I will search manually. I can’t do it with query loop because the pages I need are custom. I would have to exclude many pages. It’s a “semantic cocoon” type of mesh
Alexis
agency K-LYAOctober 2, 2022 at 11:22 pm #2361102Fernando Customer Support
You’ll need a new Shortcode. Try adding this:
function get_estimated_reading_time($attr) { ob_start(); $options = shortcode_atts( array( 'my-id'=> '1' ), $attr); $post = get_post($options['my-id']); $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 ); echo '<div class="read-time"><span>Temps de lecture </span>' . $time . ' min</div>'; return ob_get_clean(); } add_shortcode('get-reading-time', 'get_estimated_reading_time');
To use this you’ll need to add the id in the parameter.
Example:
[get-reading-time my-id="396774"]
Replace
396774
with the ID of the post you want to retrieve the time of.October 3, 2022 at 2:33 am #2361248alexis
Perfect it’s ok
Alexis
agency K-LYAOctober 3, 2022 at 5:03 pm #2362068Fernando Customer Support
You’re welcome Alexis!
October 28, 2022 at 2:48 am #2391146Jacopo
Hi, this is a very good cue in my opinion.
I am trying to insert a “read time” to my posts and I too noticed that Yoast already calculates it automatically.
<meta name="twitter:data2" content="1 minuto" class="yoast-seo-meta-tag" />
So why put code in functions.php and create shortcodes if you can directly take the data created by Yoast?
Is there any way to do this using for example a Headline block of GenerateBlocks, set Dynamic Options and Post meta as Dynamic text type?
I hope I have explained myself.
Thanks in advance for the help ๐
October 28, 2022 at 4:48 am #2391293David
StaffCustomer SupportHi there,
looking at the Yoast documentation – they have their own block to display it:
https://yoast.com/help/estimated-reading-time-in-yoast-seo/
Or alternatively if you want to use the a Headline block, then you would need a shortcode for that.
Elvin provided one here:https://generatepress.com/forums/topic/creating-a-shortcode-with-yoast/#post-1891293
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/October 28, 2022 at 7:07 am #2391491Jacopo
Thank you VERY MUCH David ( and Elvin ๐ )
October 28, 2022 at 8:29 am #2391841David
StaffCustomer SupportYou’re welcome
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/ -
AuthorPosts
- You must be logged in to reply to this topic.