- This topic has 17 replies, 3 voices, and was last updated 3 years, 11 months ago by
Tom.
-
AuthorPosts
-
June 14, 2019 at 1:48 am #929239
Huy
Hi guys
I am using Page Header elements for almost pages on my website and really like this feature
I wonder if have any way to display the meta description of the page/post on the Page Header? I looked for some Template tags but it seemed that tag wasn’t there
I hope you can help me, thank you so so much
June 14, 2019 at 2:48 am #929293David
StaffCustomer SupportHi there,
how are you adding the post meta description? With an SEO plugin? As this may require writing a shortcode to use to output the content in the header element.
June 14, 2019 at 4:10 am #929348Huy
Hi David
I use Yoast SEO to add the post meta description. I have to first create the shortcode then I can fill it in Header, right?
June 14, 2019 at 2:08 pm #929989David
StaffCustomer SupportSo we could create a shortcode with this PHP Snippet:
function db_page_hero_excerpt() { ob_start(); $meta_desc = get_post_meta(get_queried_object_id(), '_yoast_wpseo_metadesc', true); if ($meta_desc) { echo '<div class="page-hero-post-meta">' . $meta_desc . '</div>'; } return ob_get_clean(); } add_shortcode( 'page_hero_meta_desc','db_page_hero_excerpt' );
Then add the
[page_hero_meta_desc]
to your header elementJune 14, 2019 at 4:19 pm #930056Huy
Hi David
THank you so so much <3 it works
June 15, 2019 at 6:08 am #930415David
StaffCustomer SupportAwesome – glad to be of help.
June 15, 2019 at 8:29 am #930629Huy
Hi David
I have some problem with the code
In this page: https://www.cyberpet.com/dogs/. The meta description of the page is:
“Find posts about dogs that are as irresistible as their puppy eyes. They are curated to give you valuable information on how to care for your canine companion.”However, The meta description o the page is not what it should be. Instead, it picked the meta description of the first post showed up in the category:
“Are you worried about your husky’s picky eating habits or coat health? A change in diet might help! Check out our list of the best dog foods for huskies.”Can you help me, please!
June 15, 2019 at 8:41 am #930647David
StaffCustomer SupportIs the problem only occurring on Archive pages?
June 15, 2019 at 4:50 pm #930901Huy
Yes. It occurs only on the archive page
June 16, 2019 at 4:59 am #931185David
StaffCustomer SupportI edited the function above can you give that a try?
June 16, 2019 at 9:04 am #931474Huy
June 16, 2019 at 1:39 pm #931638David
StaffCustomer SupportDoes it still display on the Single Posts? If so i am a little stumped by this, you may need to speak with Yoast to see if they can advise on how to display this.
June 16, 2019 at 11:48 pm #931856Huy
Actually, I only use this code to display the meta description of the archive page. I don’t use this in Single Post
Does that make the problem easier?
June 17, 2019 at 9:05 am #932499Tom
Lead DeveloperLead DeveloperWhere is the meta description input for the archives? Is there a setting in the global Yoast options?
June 17, 2019 at 5:13 pm #932808Huy
I edit the meta description for the archive by Yoast SEO, like editing a normal post: http://prntscr.com/o35nwe
-
AuthorPosts
- You must be logged in to reply to this topic.