Yoast SEO
[resolved] [Plugin: WordPress SEO by Yoast] Template tag or similar to get WordPress SEO Description (2 posts)

  1. alexleonard
    Posted 4 years ago #

    Hi there,

    I'm just in the process of finalising my site and want to use Google's meta tags for customising the +Snippet in a +1 share.

    <meta itemprop="name" content="Title of your content">
    <meta itemprop="description" content="This would be a description of the content your users are sharing">

    I can populate the first field just using

    <meta itemprop="name" content="<?php wp_title(); ?>">

    However, I would like to access the WordPress SEO generated description to populate the second meta element.

    Is there a template tag I can use, or some other way to get this information?

    Cheers for the awesome plugin!


  2. alexleonard
    Posted 4 years ago #

    Ok, I've worked this one out.

    I've got the following code in my head to prepare the correct itemprop items as per Google+ requirements.

    <!-- Add the following three tags inside head -->
    	<meta itemprop="name" content="<?php wp_title(); ?>">
    		$postCustom = get_post_custom($post->ID);
    		$yoastMetaDescription = $postCustom['_yoast_wpseo_metadesc'][0];
    		if ($yoastMetaDescription) {
    			echo '<meta itemprop="description" content="' . $yoastMetaDescription . '">' . "\n";
    		if ( has_post_thumbnail($post->ID) ) {
    			$featuredThumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'standard-list-thumb');
    			echo '<meta itemprop="image" content="' . $featuredThumb[0] . '">';

    I'm using 'standard-list-thumb' as my image size, but you'll need to replace it as you see fit.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Yoast SEO
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic