Archived topic
Yoast Meta Description as Excerpt below Post Title
15 replies · Started by Chitika on November 1, 2020
I write my meta description using Yoast Plugin.
There are about 400 posts.
Now I want to display this meta information below post title, just like branded sites.
Is it possible?
Hi there,
you can display the yoast meta description using this PHP snippet:
<?php echo get_post_meta(get_the_ID(), '_yoast_wpseo_metadesc', true); ?>
You can use a Hook Element to add that meta where you require it:
https://docs.generatepress.com/article/hooks-element-overview/
How to display it after post title.
Also I would like it to be H3 Tag with some color coding.
You would use the generate_after_entry_title Hook with a priority of 5
You can see all hooks here:
https://docs.generatepress.com/article/hooks-visual-guide/
Changing it to H3 you could try this instead:
<?php echo '<h3>' . get_post_meta(get_the_ID(), '_yoast_wpseo_metadesc', true) . '</h3>'; ?>
Not sure it will work correctly but that as much as we can do as we're not in control of Yoasts shortcode.
You would use the generate_after_entry_title Hook with a priority of 5
I have used the above location. But it displays before post title or after breadcrumbs. I even made the priority of 3. Same result.
How have you added the description text into the Entry Header ?
Frankly I didn't understand your question.
I added the raw code you gave me.
BTW, this is the support answer received from plugin support.
https://wordpress.org/support/topic/display-yoast-meta-description-after-post-title/#post-13637192
See here:

Your site has content being displayed before the Post Title - this is not a standard function of the theme. So how did you add this Content ?
Actually that is the "Yoast Meta Description" as you suggested with generate_after_entry_title hook.
BTW, I'm also using Yoast Breadcrumbs code to display using generate_before_content hook.
You have this CSS:
.entry-header {
display: flex;
flex-direction: column-reverse;
}
Delete that and it will return the order to below the title.
I have deleted it. But it still shows about title.
I have cleared all the cache too.
I can still the CSS on your site - can you clear your plugin/server caches ?
Thanks @David. It seems the Varnish and Cloudflare cache are taking some time to clear.
Now I see the changes. Also, I tried to make the color of the meta to Red and it works.
So probably the <h3> tag also should work.