{"id":517,"date":"2012-05-17T15:02:18","date_gmt":"2012-05-17T06:02:18","guid":{"rendered":"http:\/\/www.santoshkori.com\/blog\/?p=517"},"modified":"2012-08-23T17:27:43","modified_gmt":"2012-08-23T08:27:43","slug":"how-to-automatically-create-meta-description-from-content-in-wordpress","status":"publish","type":"post","link":"https:\/\/www.santoshkori.com\/blog\/how-to-automatically-create-meta-description-from-content-in-wordpress\/","title":{"rendered":"How to automatically create meta description from content in wordpress"},"content":{"rendered":"<p>By default, WordPress do not add a &lt;meta description&gt; tag to your  blog. While not necessary, some SEO experts insists that this tag is  important for your site SEO. So what about generating one using your  post content? Here is a cool piece of code to do it easily.<!--more--><\/p>\n<p>The Meta description tags should have relevant keywords to the article to attract visitors to your site.<\/p>\n<p>In WordPress it can be done by using SEO plugins,  but if you don\u2019t have these plugins installed or forgot to add the meta  description to this plugin then here is the WordPress snippet for you.<\/p>\n<p>This  snippet will automatically take the first 125 characters of your  content and add this into the meta description tag for the page.<\/p>\n<p>Paste the following code into your <em>functions.php<\/em> file:<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\nfunction create_meta_desc() {\r\n    global $post;\r\nif (!is_single()) { return; }\r\n    $meta = strip_tags($post-&gt;post_content);\r\n    $meta = strip_shortcodes($post-&gt;post_content);\r\n    $meta = str_replace(array(&quot;\\n&quot;, &quot;\\r&quot;, &quot;\\t&quot;), ' ', $meta);\r\n    $meta = substr($meta, 0, 125);\r\n    echo &quot;&lt;meta name='description' content='$meta' \/&gt;&quot;;\r\n}\r\nadd_action('wp_head', 'create_meta_desc');\r\n<\/pre>\n<p><strong><em>Thanks to <a href=\"http:\/\/www.paulund.co.uk\/automatically-create-meta-description-from-content\" target=\"_blank\" rel=\"noopener\">Paul<\/a> for this handy snippet!<\/em><\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>By default, WordPress do not add a &lt;meta description&gt; tag to your blog. While not necessary, some SEO experts insists that this tag is important for your site SEO. So what about generating one using your post content? Here is a cool piece of code to do it easily.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[230],"tags":[232,231,725],"class_list":["post-517","post","type-post","status-publish","format-standard","hentry","category-wordpress-seo","tag-how-to-automatically-create-meta-description-from-content","tag-how-to-automatically-create-meta-description-from-content-in-wordpress","tag-wordpress"],"_links":{"self":[{"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/posts\/517","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/comments?post=517"}],"version-history":[{"count":3,"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/posts\/517\/revisions"}],"predecessor-version":[{"id":686,"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/posts\/517\/revisions\/686"}],"wp:attachment":[{"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/media?parent=517"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/categories?post=517"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/tags?post=517"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}