Nofollow SEO for your WordPress Functions

November 7, 2008

in Code, SEO, WordPress

Link Condom

Pretty crude idea of nofollow, isn't it?

While working on a recent website, I became frustrated by the lack of nofollow support in many WordPress functions.  Make that, most WordPress functions.

There are a few WP functions that I wanted to add nofollow to, so here’s a list and a download link:

Download the nofollow_functions.php file

next_posts_link() → nofollow_next_posts_link()

When you’re in a single post, you can use next_posts_link to generate a link to the next post.  The title can be the name of the next post, or something as simple as…well…”next post”. If you’re using your blog title as the anchor text, you already will have the same link coming from your archives page — and probably inside a H2, which is much more valuable. To give that link more weight, we add nofollow. If you have some other text, like “next post”, then you definitely will want nofollow.

previous_posts_link() → nofollow_previous_posts_link()

Same issues as nofollowing the next_posts_link() function.

post_comments_feed_link() → nofollow_post_comments_feed_link()

I didn’t want search engines spending their time indexing the comments feed for each post — they should be automatically checking the new comments anyway, so why have that issue arise?  Nofollow it is!

comments_popup_link() → nofollow_comments_popup_link()

If you have a link to leave a comment on your archives or index page of your blog, you have a slew of links that say “leave a comment” or something similar. That’s just not great link sculpting going on there, now is it? Nofollow it is!

next_image_link() → get_next_image_link() &
previous_image_link() → get_previous_image_link()

In an attachment.php file, next_image_link() and previous_image_link() are similar to next_posts_link() and previous_posts_link() — except they provide links to the next image in the gallery, rather than the next post in the blog. I wanted to be able to have the functions return a value rather than echo one, so I added these functions that keep the WordPress structure of adding get_ before a function to represent it does the same thing.

the_category → nofollow_the_category &
get_the_category →  nofollow_get_the_category &
get_the_category_list → nofollow_get_the_category_list

Added 2/20/09: I’ve modified these category functions to be nofollow.  If you want to list the categories your post is in without having them followed, use these functions instead of your standard ones.

Installation

Once you download these WordPress nofollow functions, if you don’t have a functions.php file yet, rename it to functions.php and copy it to your theme’s folder.  If you do have a functions.php file, copy and paste the code into the file. Then, use the nofollow versions of the functions in place of the standard versions in your theme.

Leave any questions in the comments below!

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • StumbleUpon
  • Technorati
  • Twitter

Related posts:

  1. Get Adjacent Images – More WordPress Functions
  2. Blog Comments Now Pass Juice – No More `nofollow`
  3. SEO Google Profiles – Google Adds NoFollow to Links
  4. SEO Randomizer: Save the Value of Your SEO'd Links
  5. How to turn off captions in WordPress 2.6

{ 19 comments… read them below or add one }

Dani November 8, 2008 at 1:33 pm

I have looked over your blog a few times and I love it.

Reply

Star Riley November 11, 2008 at 4:24 am

Your 11 top wordpress plugins was cool I’m not 100% about this but I’ll check it out thanks for the info.

Reply

Douglas Karr December 24, 2008 at 11:21 am

Your timing on this is great. I was just noticing my site had some page links indexed that I didn’t want. I inserted your code into my functions.php, updated my theme, and voila!

Reply

Zack Katz December 24, 2008 at 11:51 am

@Doug – Thank you, your plugins have helped me out hundreds of times. :-)

Glad I could help back.

Reply

saravanakumar January 22, 2009 at 2:52 am

Nice post! Especially the topic about WP plugin. Very informtive. Thanks.

Reply

Stever February 18, 2009 at 8:38 pm

grrrrr, added the one for comments popup link to functions.php and nothing happens. There is a call to comments_popup_link function in index.php.

Using 2.7.1

Any ideas?

Reply

Zack Katz February 18, 2009 at 9:50 pm

@Stever – You’ve got to rename the function to nofollow_comments_popup_link instead. Then use that in your theme.

Reply

Stever February 19, 2009 at 12:29 am

aha, was assuming the new function was over riding the default one. Did the switcheroo and it works now.

Thanks man.

Reply

Peter February 20, 2009 at 3:00 am

Awesome, thanks for this! Any way to create a new nofollow function for the “the_category”?

It would be nice if there was a easy way to nofollow the categories that posts are located in under the post title itself.

For example:

by Filed Under:

Suggestions?

Reply

Peter February 20, 2009 at 3:02 am

Err I just realized you can’t post code….basically the structure would be:

[Post Title]
[The Date] by [The Author] – Filed under [The Category]

I haven’t found any simple solutions yet :(

Reply

Peter February 20, 2009 at 12:40 pm

Zack, you’re the man!

Did you perhaps forget to update the .txt file on your website? I searched the document for nofollow_the_category() but didn’t find anything?

Reply

Zack Katz February 20, 2009 at 1:03 pm

@Peter – search for nofollow_the_category instead (without the ()). It’s at the bottom there.

Reply

Stever February 23, 2009 at 3:15 am

Here’s one I just came across for no-indexing your page 2, 3, 4 (0ff of home page). Add it to header.php

if(is_home()){
if ($pages>=2) {
echo ”;
}
}

Now your next-previous links, or if you are using pagination, will flow link juice to these deeper pages but only the post page itself gets indexed. I use no-index on archives and categories too.

Reply

Stever February 23, 2009 at 3:16 am

oops, can’t post the code in the echo. Basically it is a meta-robots-noindex tag.

Reply

static brain May 18, 2009 at 7:34 pm

Does anyone know of a way to add no follow to just the comments page itself in 2.7.1 I have tried every plugin out there and can’t find the answer. I don’t want a duplicate url. A comment url adds the word respond to the url like this http://www.staticbrain.com/archive/google-free-411-call-1-800-goog-411/#respond
it also is adding urls with comments at the ends like this
http://www.staticbrain.com/archive/are-bald-women-sexy/#comments
I need a hack to fix it. Even platinum seo plugin wont work for it. This is depressing. If anyone can help me please let me know. Thanks.

Reply

static brain May 20, 2009 at 9:43 am

Thank you I will check into that. :-)

Reply

Zack Katz February 20, 2009 at 10:29 am

@Peter – I’ve added the functions you will need to the bottom of the file (mainly nofollow_the_category()). Enjoy!

PS – To post code in comments, you need to format it so that > is &gt; and < is &lt;, and for good measure, wrap the entire code in <code> </code> tags.

Reply

Zack Katz April 8, 2009 at 2:28 pm

I believe the code should be if($paged > 1), rather than $pages. Thanks for the tip!

Reply

Zack Katz May 18, 2009 at 9:29 pm

What you’re probably looking for is this plugin: http://yoast.com/wordpress/canonical/

Reply

Leave a Comment

Previous post:

Next post: