How to Add WordPress Meta Description Tags Without a Plugin




by Tammy


You can add meta descriptions to your WordPress without a plugin. Image: {link url="http://www.norebbo.com/more-3d-renderings-of-metallic-wordpress-logos/" rel="nofollow"}Norebbo{/link}

You can add meta descriptions to your WordPress without a plugin.
Image: Norebbo

When an update made it impossible to open the WordPress Dashboard, the problem ended up being an incompatible SEO plugin that shut everything down. Of all the search engine optimization features, meta descriptions are the most important for us. The plugin worked great before the update (and it probably would have been fixed shortly enough), but a website or a blog really shouldn’t be so dependent on a single outside add-on.

With this in mind, we decided to find out how to add WordPress meta descriptions without a plugin. It is a manual solution, so if you are looking for something to add meta tags automatically, you might want to stick with one of the SEO plug-ins that will create descriptions on the fly. Or you could switch to Genesis at StudioPress.com, and it will take care of it for you.

For those who want to try it manually, there are four main sections that should have meta descriptions. That is the front page, single posts, categories, and pages.

Front Page WordPress Meta Description

If you are wanting to add a meta description without a plugin to your front index page, copy and paste the below code into your WordPress theme’s header.php file, anywhere between <head> and </head>. It might be easier to find if you paste it right below the title codes.

The code:

<?php if ( (is_home()) || (is_front_page()) ) { ?>
<meta name="description" content="Type your main page meta description here." />
<?php } ?>

Change the description to your own, save the file and upload it back into your theme’s main folder. Refresh or reload your index page, then check your source code to see the results.

Single Posts WordPress Meta Descriptions

To manually add meta descriptions to single posts on your WordPress blog, it could take a while if you have a large site. If it’s too big, you might want to consider another option, but it does work.

This uses the Excerpt section of individual posts. If you don’t see it when you Edit a post, click Screen Options in the top right corner of your WordPress Dashboard and put a check in the box next to Excerpt. Click Screen Options again to close the open panel.

Edit every post on your site and type a description in the Excerpt box below the post. Click Update each time you’re done.

When you have finished typing descriptions for each post, reopen your theme’s header file, but this time add the next tags (in blue) to the above code.

<?php if ( (is_home()) || (is_front_page()) ) { ?>
<meta name="description" content="Type your main page meta description here." />
<?php } elseif (is_single()) { ?>
<meta name="description" content="<?php echo get_the_excerpt(); ?>"/>

<?php } ?>

Categories WordPress Meta Descriptions

In your WordPress Dashboard, click on Categories in the top left Posts section. Click to edit each individual category and, if you haven’t already, type a description for the page. When this is done, you are going to add another tag to the code above in your header file. Add the code below in blue to include your category descriptions.

<?php if ( (is_home()) || (is_front_page()) ) { ?>
<meta name="description" content="Type your main page meta description here." />
<?php } elseif (is_single()) { ?>
<meta name="description" content="<?php echo get_the_excerpt(); ?>"/>
<?php } elseif (is_category()) { ?>
<meta name="description" content="<?php echo category_description(); ?>"/>

<?php } ?>

Tip: If this adds paragraph codes (<p> </p>) around your description, open your theme’s functions.php file and add the following remove_filter code. You can add it to the very bottom of the file. Save and re-upload when done.

Add to functions.php:
remove_filter('term_description','wpautop');

Pages WordPress Meta Descriptions

For the last update, you can add meta descriptions to an individual page by adding the following code to your header codes above. Rather than calling a description from the script, you will type the description in the actual codes below, as you’d done for the index page. Where it’s written yourfirstpage, yoursecondpage, yourthirdpage, you will change these to each page slug or page ID, then type the description where it says. If you have more or less than 3 pages, you can copy or delete the codes as needed.

Read more about conditional tags.

<?php if ( (is_home()) || (is_front_page()) ) { ?>
<meta name="description" content="Type your main page meta description here." />
<?php } elseif (is_single()) { ?>
<meta name="description" content="<?php echo get_the_excerpt(); ?>"/>
<?php } elseif (is_category()) { ?>
<meta name="description" content="<?php echo category_description(); ?>"/>
<?php } elseif (is_page( 'yourfirstpage' )) { ?>
<meta name="description" content="Type the description for your first page."/>

<?php } elseif (is_page( 'yoursecondpage' )) { ?>
<meta name="description" content="Type the description for your second page."/>

<?php } elseif (is_page( 'yourthirdpage' )) { ?>
<meta name="description" content="Type the description for your third page."/>

<?php } ?>

There is a lot of work involved when you first add WordPress meta descriptions without a plugin, but once everything is set up, all you have to do is type a description in the Excerpt section every time you publish a new post. Consider it as a backup plan if your favorite SEO plugin stops functioning properly.

It’s easy to write meta tags for your HTML website. Find out how.