How to add meta descriptions in Yoast SEO plugin

Yoast SEO plugin is one of the most popular SEO plugins. According to the data shown on WordPress, there It add basic meta tags automatically are over 5 million websites using this plugin for their SEO and content optimization. Both free and premium versions of the plugin support customization of meta description. If the meta description is missing, you will receive alert under SEO analysis section for the post. The problem is it’s not clear how to generate meta descriptions in Yoast SEO plugin automatically.

Why does meta description matter?

The meta description is an attribute of meta tag that gives a brief summary of a web page. Search engines such as Google may display the meta description in search results. Although neither meta descriptions nor meta keywords have been the ranking factors as announced by Google in 2009, meta descriptions serve as advertisement for your web page. So it will impact CTR of your webpage should it appear in the search results. In this perspective, Yoast is right to force you to write quality meta descriptions manually.

On the other hand, Yoast SEO plugin does create OpenGraph meta descriptions even without html meta descriptions. If you have manfully created html meta description, OpenGraph meta description will be replaced with content of html meta description for the post. But there’s no vice versa.

How to create meta description in Yoast SEO plugin

Manually add meta description

  1. In WordPress, go to the Edit screen for a page/post
  2. Scroll down to the Yoast meta box
  3. Click on ‘Edit Snippet’
  4. Input a page description into the ‘Meta Description’ box
  5. Click ‘Update’ to save the changes to the page/post

Add meta description using other WordPress plugin Automatically

That said, it’s not so clear in how to generate meta descriptions in Yoast SEO plugin automatically. To remove missing meta description issue, some websites are seen to install another plugin such as Add Meta Tags wordpress plugin. It adds basic meta tags automatically as well as similar metas to those by Yoast SEO plugin, such as Opengraph, Twitter Cards etc.

Add meta description with PHP scripts Automatically

While it’s handy to use other plugin, there’s obvious drawback. It’s redundant and may cause duplicate or inconsistent meta descriptions. When you manually update the meta descriptions in Yoast SEO plugin, the plugin will create a basic meta description tag, which could be different from that by Add Meta Tags wordpress plugin.

You could add the following PHP codes in functions file of your theme to remove missing meta description issue with Yoast Plugin.

function generate_meta_descriptions() {
  $frontend = WPSEO_Frontend::get_instance();
  $des = $frontend->metadesc( false );
  if ($des=='') {
    if ( WPSEO_Frontend_Page_Type::is_simple_page() ) {
      $post_id = WPSEO_Frontend_Page_Type::get_simple_page_id();		
      $ogdesc  = WPSEO_Meta::get_value( 'opengraph-description', $post_id );
				
      if ( ! is_string( $ogdesc ) || ( is_string( $ogdesc ) && $ogdesc === '' ) ) {
       $ogdesc = str_replace( '[…]', '…', wp_strip_all_tags( get_the_excerpt() ) );
       }
			
    }
  echo '' . "\n";
}
}
add_action('wp_head', 'generate_meta_descriptions');


Add meta description using Yoast meta template variable

Besides, you can set up meta description templates by the following steps.

  1. Going to SEO on the left menu bar
  2. Click Search Appearance
  3. Click Content Types
  4. Enter the meta template variable %%excerpt%% for ‘Meta description template:’ for each specific type of content (pages, posts, etc)

Now the excerpt of each post will be the content of meta description for each post as default. When you update in ‘Meta Description’ box manually, the updated one will replace the default content.

In conclusion, with the introduction more and more functions, the basic SEO feature seems hidden in the Yoast SEO plugin. This article summarizes all options to add meta description in the Yoast SEO plugin. The best practice might be manually updating in ‘Meta Description’ box in order to generate quality meta descriptions. Of course, using template variables could be used as fallback solution to cope with missing meta description issue.

Leave a Reply

Your email address will not be published. Required fields are marked *