How to add unique meta description tags in WordPress without plugins

When I checked my website for errors in the Google Search Console earlier this morning, I noticed a warning about duplicate meta descriptions on my WordPress website. I had 205 pages with duplicate tags and at first I didn’t think much of it, but I decided to find out the significance in terms of better SEO just in case. I was shocked to realise that having duplicate meta description tags throughout your WordPress blog is a bad idea and Google doesn’t like it one bit!

Google: Don’t duplicate meta description tags

Google’s Matt Cutts has officially stated in his video that it’s better to have no meta description tag than to have numerous duplicate meta description tags on all of your pages and categories. This is especially frustrating because by default most WordPress templates have only the one description tag displayed throughout the entire website. Check out this video with Matt explaining everything:

Unique meta description without plugins

It’s clear that Google doesn’t endorse the use of duplicate description tags and there are numerous plugins available that try to work around it (YOAST for example) and while I don’t personally have anything against these plugins, one might still consider avoiding them in order to gain better website loading speeds because it’s common knowledge that having too many plugins active on your WordPress site can actually slow down the loading speeds and make the end user experience that much more annoying.

Just a few lines of code

In your header.php file remove the default <meta name=“description” content=“Your description”/> and instead use the following code:

<?php if ( is_home() ) { ?>
<meta name="description" content="Your main and most important description shown on homepage"/>
<?php } ?>
<?php if ( is_single() OR is_page() ) { ?>
<meta name="description" content="<?php { setup_postdata($post); echo esc_attr(htmlentities(get_the_excerpt())); } ?>"/>
<?php } ?>

The above code uses conditional statements to check whether the currently displayed page is either a homepage, a single post or a single page and then uses “Your main and most important description shown on homepage” on your homepage and the default post excerpt in the description of posts and pages respectively.

In my experience you don’t really need to display the description tag anywhere else so I removed it from elsewhere. And in case you’re worried, Google is fairly good at coming up with descriptions for the rest of your page so your search results should still look very nice.

Double check just in case

This code works on my template, but you should still double check so after editing the header.php and replacing it with the original try refreshing your page (ctrl + F5) and then view the page source, especially the meta description tag, and see if it’s working. First try it on the homepage (main index) and then click on any posts or pages you may have and view the source on those pages also. If you see the post excerpt inside the description tag it means everything is working as it’s supposed to.

Author: ynef

29 year old freelance writer and web developer. A technophile who appreciates and respects mother nature in all of its glory. Favorite skills in Runescape include Farming, Herblore and Magic.


You may also like