Apr 27 2008

Wordpress homepage SEO Optimization

Wordpress is great software but it’s not as SEO optimized as many people think and the use of HTML header tags is certainly an area for improvement. There is a simple way to improve the HTML structure and SEO optimization of the home page, as I’ll discuss here.

As we showed in a previous post, H1 tags are not SEO optimized in out of the box Wordpress and most themes, so it is advisable to correct this if you are seeking maximum SEO benefits for your blog. Doing that then brings you to another issue that is actually even more simple to correct, and yet improves both the HTML structure of your home page and also its SEO performance.

So what is the problem to correct?

If you look at the source of almost any Wordpress driven blog, you will see that every post title is assigned H2 tags. Actually that is OK, apart from one simple fact. Presumably the most important post, at any given time, is your most recent post. You therefore want your latest post to be assigned with h1 tags, which immediately tells the search engines to give this blog title more importance.

So we need a way to automatically assign the latest post title on your homepage an h1 instead of an h2 tag. However you should only do this once you have corrected the h1 tag problem mentioned in our previous article.

Dynamically assigning the latest post on your homepage with an h1 tag, rather than an h2 tag does involve a very small amount of PHP programming. Sorry about that, but believe me, it is not difficult and it does help your blog with the search engines.

Just to show you that we practise what we preach, take a look at the source code of the home page of this site, Medianetrix.com. You can see that the latest blog post title has an h1 tag and older posts titles are assigned h2 tags.

This is how to do it, so take a big breath and lets dive into some PHP….

The blog home page is controlled, in most themes, either by a script called index.php or home.php. These reside in your themes root directory and so are easy to find.

Once you have found the right script, then we are going to add some very simple PHP to the code that controls the Wordpress loop. Just in case things go wrong - take a copy of the script first!

Simply search for this code in your script (this is the start of the famed loop):

<?php if (have_posts()) : while (have_posts()) : the_post();?>

Change the code to this by copy and pasting this new code over it:

<<?php if (have_posts()) : ?>
<?php $mn_header_tag = "h1";
while (have_posts()) : the_post();
?>

Now replace the h2 header tags that display the blog title, which you can find by searching for this:

the_title();

with this code:

<?php echo $mn_header_tag;?>

Remember to close the h2 tags with this new code snippet too.

The last thing to change is to add this code at the end of the loop, which you can find by searching for endwhile;

Add this code just before the endwhile statement at the end of the loop:

if ( $mn_header_tag == "h1" )
{$mn_header_tag = "h2";}

Save your edited script and upload it into the theme directory on your web server and you will find that the latest post on your home page will be assigned an h1 tag, and older blog titles wil be assigned h2 tags.

I guess this may seem very tricky to do to someone with no PHP skills, however it is is extremely simple to implement for any competent PHP programmer or web designer conversant with Wordpress.

Gaining good performance in search engine results for your blog or website is a constant competition with other sites so any advantage that you can give to your website by using good SEO and HTML coding practises, is a good investment.

Just a few notes and thoughts for PHP programmers who may be reading this blog:

  1. There may be a native Wordpress tag to identify record number in the Wordpress loop. We can’t find one, hence using the code that we have described. If there is a suitable tag, then use that instead. If there isn’t one, then please Wordpress, is it possible for there to be one in later releases!
  2. We named our new variable mn_header_tag this way to ensure that there are no conflicts with variables in the Wordpress or plugin code. You can actually call it what you want.
Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • e-mail
  • Slashdot
  • Reddit
  • Technorati
  • Ma.gnolia
  • Spurl

Tags:
Posted under Wordpress |


One Response to “Wordpress homepage SEO Optimization”

  1. Hey boys, thanks for sharing your techniques with us. However I failed to implement this one here and I’m not sure why. I get this with the h1:
    <
    Title

    And this with the h2 titles:
    if ( $mn_header_tag == “h1″ ) {$mn_header_tag = “h2″;}
    Title

    What’s gone wrong? Thanks for helping me out here :)

Post a Comment