Friday, May 18, 2012

How to automatically create meta description from content in wordpress

How to automatically create meta description from content in wordpress


WordPress by default don't add a "meta description" tag to into blog. Its not necessary, but some SEO experts insists that this tag is important for our website SEO purpose. So isn't it a great idea about generating a "meta description" using the post content? In below I have describe a useful code which can do this purpose easily.
For this please paste the following code into the functions.php file under theme folder

function create_meta_desc() {
global $post;
if (!is_single()) { return; }
$meta = strip_tags($post->post_content);
$meta = strip_shortcodes($post->post_content);
$meta = str_replace(array("\n", "\r", "\t"), ' ', $meta);
$meta = substr($meta, 0, 125);
echo "< meta name='description' content='$meta' />";
}
add_action('wp_head', 'create_meta_desc');
The code is ready now

No comments:

Post a Comment

I just got my #domain @BigRock. Get upto 25% off with my personalized coupon link Get upto 25% off