« Are You Making the Most of Your Time? | | How to Prepare to Sell a Web Site from Day One »
Dynamically Follow and Nofollow Links in a WordPress Blog Footer and Sidebar
By Dewald Pretorius | October 1, 2007
One of the many guidelines that Dan Thies gives in his awesome SEO Fast Start book and in this Dynamic Linking & Nofollow blog post, is that one must “nofollow” links to your site map page (and other “overhead” pages) from all the other pages on your site, except from the home page. That way the search engine spiders can find your site map page, while the page does not dilute the internal link juice of the other site pages.
Implementing Dan’s guideline on a WordPress blog is not a simple exercise, but here’s how you do it.
The method I’m going to show you allows you to selectively nofollow hard-coded links in your WordPress blog’s footer and sidebar. It does not work for links that are dynamically generated by the WordPress system, such as the Blogroll.
The first to-do is to create a file called “functions.php” and save it in your WordPress theme folder. Some themes come with a functions.php file. If that’s the case, then you must edit that file.
If your blog is installed in the root folder of the domain (http://www.example.com/), then put the following code in the functions.php file:
function this_is_home() {
$url = $_SERVER["REQUEST_URI"];
$url_array = explode("/",$url);
array_shift($url_array);
if(empty($url_array) or $url_array[0] == "")
return true;
} else {
return false;
}
}
?>
If you’re editing an existing functions.php file, don’t copy the “<?php” and “?>” lines. They’ll be in the file already.
If the blog is installed in a subfolder of the domain (http://www.example.com/blog/), then put the following code in the functions.php file:
function this_is_home() {
$url = $_SERVER["REQUEST_URI"];
$url_array = explode("/",$url);
array_shift($url_array);
if($url_array[0] == "blog")
return true;
} else {
return false;
}
}
?>
Replace ‘blog’ with the subfolder name where your blog is installed.
At this point in time you might be asking, why don’t I use the built-in “is_home()” function of WordPress?
I’ve had all kinds of weird issues with is_home. Sometimes it would work, other times it wouldn’t work, especially when you have a WordPress static page as the home page of the blog. So, I wrote a function that will reliably determine if the current page is the home page of the blog.
The second to-do is to edit your WordPress theme’s “footer.php” file.
Insert the following code in footer.php where you want the sitemap link to appear.
You can repeat this second to-do for all the links that you want to have “followed” on the home page and “nofollowed” everywhere else.
This is the key part of the solution: <?php if (!this_is_home()) echo " rel=\"nofollow\""; ?>. Insert that in any hyperlink that you want to dynamically follow and nofollow.
In the end it’s not too difficult, and it will preserve a lot of internal link juice on the internal pages of your blog that can then flow to the pages you want to rank higher in the SERPs.
Tags: danthies, SEO, seofaststart, wordpress
Topics: SEO |
Other Posts That May Interest You
- WP Spinner - Released in the Wild
- How to Install and Configure a WordPress Blog
- How to Break Out of HTML Frames
- WordPress Affiliate Pro Review
- WP SEO Sniper Released





January 27th, 2010 at 1:59 am
I have tried the above code in my functions.php file WP version 2.84 and it is crashing the site.
Have you tried it with a newer version of WP since this post?
February 2nd, 2010 at 11:05 am
Great tip. Thanks! Just remove an extra “}” in front of “else”. Otherwise you’ll get “syntax error, unexpected T_ELSE”.