Title: API for auto-generated description
Last modified: February 1, 2019

---

# API for auto-generated description

 *  Resolved [Jim Reekes](https://wordpress.org/support/users/reekes/)
 * (@reekes)
 * [7 years, 2 months ago](https://wordpress.org/support/topic/api-for-auto-generated-description/)
 * I’ve searched for a couple hours, and tried several coding ideas in PHP. I’m 
   stuck. I need the default description created by yoast for the schema code I’m
   adding. I’ve ended up writing a complicated function to create a proper excerpt
   but I can’t match the one I get yoast creating.
 * I would like to get a copy of the default yoast auto-generated meta-description.
   I’m not referring to the excerpts I wrote and entered into yoast. Those I can
   get in my PHP code (see below). I’m asking about the default excerpt yoast creates
   when there isn’t one manually added to the yoast panel with the post editor.
 * This call returns null when there is no manually entered desc. It works only 
   if there was one written manually.
 * `get_post_meta($post->ID, '_yoast_wpseo_metadesc', true)`
 * These WordPress functions also do not produce the default yoast excerpt: `get_the_excerpt()`
   and `the_excerpt()`
 * Yet there *is* a nicely filtered description created and outputted as meta name
   =”description” and og:description.
 * My question, how to I get that same default except for use in my PHP template?

Viewing 7 replies - 1 through 7 (of 7 total)

 *  [Pcosta88](https://wordpress.org/support/users/pcosta88/)
 * (@pcosta88)
 * [7 years, 2 months ago](https://wordpress.org/support/topic/api-for-auto-generated-description/#post-11171508)
 * Hi,
 * While we are not sure what version of Yoast you are using the current versions
   of Yoast do not automatically generate a meta description if none has been added.
 * Google, in this instance will see no meta has been outputted and create one automatically
   for you. Google has gotten very good at scanning the site, interpreting what 
   is on it, and then creating a meta description it thinks works.
 * However, Facebook is not. This is why the og:description takes the first couple
   sentences of the post/page as the description. Facebook needs the tag in order
   to show the right content.
 * While we are not familiar with the PHP template you are using if it will have
   words and content on it, you can expect Google to create a meta description for
   it based on what it finds.
 *  Thread Starter [Jim Reekes](https://wordpress.org/support/users/reekes/)
 * (@reekes)
 * [7 years, 2 months ago](https://wordpress.org/support/topic/api-for-auto-generated-description/#post-11171937)
 * I’m using the latest versions: WordPress 5.0.3 and Yoast 9.5
 * Your plugin does create an auto-generated expert. To enable this feature, you
   add the %%excerpt%% variable to the Excerpt field in Search Appearance template.
 * The description for this is in your documentation. It reads: “Replaced with the
   post/page excerpt (or **auto-generated if it does not exist**)”
 * This auto-generated except appears on the front-end html page within the meta-
   description tag, as well as og:description and twitter:description.
 * I’m building the schema for my pages, and I must add a description. It’s not 
   an option to leave it out. In the case there wasn’t an except manually created,
   I want to use the auto-generated one created by your plugin.
 * Back to my question…How can I access the Yoast auto-generated excerpt from PHP?
    -  This reply was modified 7 years, 2 months ago by [Jim Reekes](https://wordpress.org/support/users/reekes/).
 *  [benvaassen](https://wordpress.org/support/users/benvaassen/)
 * (@benvaassen)
 * [7 years, 2 months ago](https://wordpress.org/support/topic/api-for-auto-generated-description/#post-11174512)
 * Hi Jim,
 * That’s not easily possible. If I understood you correctly, the following piece
   of code should work though:
 *     ```
       $content = strip_shortcodes( $this->args->post_content );
                       $content = wp_strip_all_tags( $content );
   
                       if ( strlen( utf8_decode( $content ) ) <= 156 ) {
                           return $content;
                       }
   
                       $replacement = wp_html_excerpt( $content, 156 );
   
                       // Trim the auto-generated string to a word boundary.
                       $replacement = substr( $replacement, 0, strrpos( $replacement, ' ' ) );
       ```
   
 *  [devnihil](https://wordpress.org/support/users/devnihil/)
 * (@devnihil)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/api-for-auto-generated-description/#post-11201731)
 * We are going ahead and marking this issue as resolved due to inactivity. If you
   require any further assistance please create a new issue.
 *  Thread Starter [Jim Reekes](https://wordpress.org/support/users/reekes/)
 * (@reekes)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/api-for-auto-generated-description/#post-11202405)
 * The inactivity is that I haven’t gotten an answer. The sample code above has 
   problems. Does Yoast have an API for getting the auto-generated excerpt?
 *  Thread Starter [Jim Reekes](https://wordpress.org/support/users/reekes/)
 * (@reekes)
 * [6 years, 8 months ago](https://wordpress.org/support/topic/api-for-auto-generated-description/#post-11778719)
 * This issue was not resolved.
 * I’m still looking for the code to get the auto-generated except created by Yoast.
 *  [sagive](https://wordpress.org/support/users/sagive/)
 * (@sagive)
 * [6 years, 7 months ago](https://wordpress.org/support/topic/api-for-auto-generated-description/#post-11904690)
 * It seems that guy didn’t understand the question or just doesn’t understand what
   you’re talking about… bad boyoast!

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘API for auto-generated description’ is closed to new replies.

 * ![](https://ps.w.org/wordpress-seo/assets/icon-256x256.gif?rev=3419908)
 * [Yoast SEO - Advanced SEO with real-time guidance and built-in AI](https://wordpress.org/plugins/wordpress-seo/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wordpress-seo/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wordpress-seo/)
 * [Active Topics](https://wordpress.org/support/plugin/wordpress-seo/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wordpress-seo/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wordpress-seo/reviews/)

 * 7 replies
 * 5 participants
 * Last reply from: [sagive](https://wordpress.org/support/users/sagive/)
 * Last activity: [6 years, 7 months ago](https://wordpress.org/support/topic/api-for-auto-generated-description/#post-11904690)
 * Status: resolved