In order to track SEO metrics for my clients, I use the SEOMoz Pro service, which is a handy tool at monitoring SEO metrics (and so much more). I’ve noticed on one of the sites I manage through the service that I’ve been missing a number of meta description tags. For those unaware, meta description tags are used to give a brief and concise summary of content on a page. This helps search engines and potential readers understand what’s on the page. The meta description info is also often used in page summaries in search results from engines like Google. The below example is one from my music site, Electric Mohawk.
The example demonstrates the importance of meta description tags in SEO quite clearly. I noticed, though, that some of my pages on Electric Mohawk are turning up as missing meta description info in their tags. A prime example for my site is archive pages. My sites are typically built using WordPress, so archive pages are dynamically generated and compiled, usually based on the month content was published.
I typically do not make my archive pages searchable for SEO purposes, but some people may still want them archived and may still want them to include a basic description. The problem is, though, that many of us already use an SEO plugin of some sort, particularly All-in-One SEO Pack, where users do not get direct access to creating meta description tags for certain dynamically generated pages (any kind of archive page or page-navi generated page). Another issue is that by creating another meta description tag to compensate for this in the header.php file would cause duplicate description tags to be created if the content is not an archive page. I’ve created a simple workaround for WordPress archive pages to solve this problem.
Add this piece of code to your theme’s header.php file:
What this code is doing is simple. The if statement checks whether or not the page is an archive page. If it is an archive page, then it will echo out a portion of the meta description html tag. In between, I made a call to the_time() function that passes in the month and year. I then created another echo that gives the actual description.
Some of you may be wondering why there are two echo statements instead of a simple string concatenation. While I was debugging and testing out this code, the date would appear before the initial HTML tag, causing problems with formatting and validation. Creating a second echo seemed to solve the problem. Also, if the statement evaluates false, no additional tags will be generated.
I hope this snippet helps you out in some way. Have an alternative? Feel free to share!
where do I place this snippet in the Header.PHP code ??
Underneath the title is where I typically add the code.