Create a Dynamic META Description function For Wordpress
December 2, 2008 · Print This Article
If you examine Google’s search result page, you’ll notice that the description (the text under the linked title) displays the page’s META description if present. Therefore, putting a different META description in each of your website’s pages is important if you want to attract clicks in search result pages where your site ranks. If your description complements the title well, you can attract more clicks. This blog uses this technique so if you go to any of my pages here, you’ll notice I have a different META description for each page.
What I’m going to show you in this post is how you can place a dynamic META description in each page of your Wordpress blog. I’m not sure if there are any Wordpress plugins out there that can do this but I find this method more efficient than installing a plugin because this only involves modifying your theme. If you’re a Wordpress theme designer, I suggest you do this in all of the themes that you make.
It’s pretty simple. You edit your theme’s header.php and add a META description tag in the head section that has a dynamic value. You can make its value dynamic by using PHP and Wordpress template tags. This is how it works.
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);
}?>" />





















Comments
Got something to say?
You must be logged in to post a comment.