How To Add Meta Descriptions To Your Posts in WordPress Using Coding ?

WordPress does not use meta description tags by default in POSTS.To create meta description tags for individual posts in your wordpress website use the following Code.

Ans:-Open your header.php file in wordpress. Then paste the following code anywhere within the <html> and</html> tags:-

<meta name="description" content="
<?php if ( (is_home()) || (is_front_page()) ) {
echo ('Your main description goes here');
} elseif(is_category()) {
echo category_description();
} elseif(is_tag()) {
echo '-tag archive page for this blog' . single_tag_title();
} elseif(is_month()) {
echo 'archive page for this blog' . the_time('F, Y');
} else {
echo get_post_meta($post->ID, "Metadescription", true);
}?>">

Note:-

For category pages, tag pages, archives and the home page, a static meta description is used. Edit lines 3, 7 and 9 to define your own. For posts, the code looks for a custom field called Metadescription and use its value fo the meta description in your worpress website.

Total Page Visits: 3602 - Today Page Visits: 2

Leave a Reply