WordPress: Dynamic Meta Description on each Post

Search Engine Optimization SEO

Your default WordPress header defines a single description of any page of your site, regardless of the page that someone landed on from a search engine. That the description in the search engine may not actually describe the post that is in the blog may result in less people clicking on your link.

I never thought about this until this weekend when I received the following review of my site by BlogStorm:

Nice, an easy one to link bait! Try adding some social bookmarking buttons on the bottom of your posts and some unique meta descriptions on each page.

Monetizing a blog like this is hard, if you try everything John Chow has tried then you will be on the right track.

With some imagination and a lot of link baiting you will be able to get enough links to rank for some really good terms (maybe you do already). Once you rank for these terms you can stick affiliate links and Adsense on the pages and reap the profits.

Getting your site reviewed is a fantastic thing because it will often identify some issue with your site that you’re not paying attention to. In this case, it’s my meta tag description for each of my posts. Meta descriptions are utilized by search engines to apply a brief description of the page listed in the results. Since people will see different pages when they search for you, why not apply different meta descriptions for each of your pages?

I already modified my header to include dynamic keywords for my keyword meta tag and it has helped improved the rankings of some of my posts. Applying different descriptions may not increase my search positioning, but as BlogStorm points out – it could lead to more interaction with my pages from the results of folks searching.

Description of the Solution

If the page in my site is a single page, such as when you click on a single post, you want an excerpt of the page. I want the excerpt to be the first 20 to 25 words of the post but I need to filter our any HTML whatsoever. Luckily, WordPress has a function that will provide me with that I need, the_excerpt_rss. Though it wasn’t meant for this use, it’s an ingenious way to apply the word limit and strip out all HTML elements!

I might even take this a step further and utilize the Optional Excerpt within WordPress to populate the meta description, but for right now this is a nice tidy shortcut! (If you use this approach AND enter an Optional Excerpt, it will utilize that excerpt for the Meta Description).

The Header Code

This function requires that you call it within The Loop, so there’s some complexity to it:

<meta name="description" content="<?php if (have_posts()&& is_single()):while(have_posts()):the_post(); the_excerpt_rss(20,2); endwhile; else: echo "My default description"; endif; ?>" />

NOTE: Be sure to replace “My default description” with whatever you currently have or would like as your blog’s meta description.

What this code does is provides the default meta description for your blog anywhere but on a Single Post page, in which case it takes the first 20 words and strips out all the HTML from it. I’m going to continue to fine tune the code (removing linefeeds) and incorporating an ‘if statement’ if there is an Optional Excerpt. Stay tuned!


  1. 1
  2. 2

    Nice one Doug, I look forward to seeing this progress. Mine is a bit of a botch job at the moment (I think), so I’m kind of glad to see someone else doing the hard work!

  3. 3

    One note – I updated the post since I thought you had to do some logic if someone utilized the “Optional Excerpt” on the post. However, you don’t have to – the Optional Excerpt will automatically be displayed if it’s utilized… another nice feature of the_excerpt and the_excerpt_rss functions.

    • 4
      • 5

        Making over $10k per month on my blog would be quite nice! However, John (a ‘virtual friend’ and person I have incredible respect for) invests a lot in paying for attention. He’s recently gotten into trouble by Google and Technorati – these could hurt him quite a bit with his revenue in the future.

        But I am appreciative that guys like him have the cahonies to push the limit – John lets guys like me know where the line is!


  4. 6
  5. 7

    How about including the category names and the blog name for each post…. does this improve on the SEO factors? I think so!

    cat_name . ','; };the_excerpt_rss(20,2); endwhile; else: ?> - " />

  6. 8

    If you’re running YAPB as your image solution, this code will pull your lead image into the meta and display it above the body when viewing the front end.

  7. 9

What do you think?

This site uses Akismet to reduce spam. Learn how your comment data is processed.