How to: Create a meta description function for your WordPress blog

December 1, 2008 at 8:04 am

Last month, I wrote a recipe about how to add meta description to your theme. Malcolm Coles, a WpRecipes reader, made some great enhancement to my original function. Here’s to create a meta description fnction.

Open your header.php file. Paste the following code anywhere within the <head> and </head> 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);
}?>">

Credits goes to Malcolm Coles for this awesome recipe!