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!
24 replies on “Nofollow SEO for your WordPress Functions”
I have looked over your blog a few times and I love it.
Your 11 top wordpress plugins was cool I’m not 100% about this but I’ll check it out thanks for the info.
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!
@Doug – Thank you, your plugins have helped me out hundreds of times. 🙂
Glad I could help back.
Nice post! Especially the topic about WP plugin. Very informtive. Thanks.
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?
@Stever – You’ve got to rename the function to
nofollow_comments_popup_link
instead. Then use that in your theme.aha, was assuming the new function was over riding the default one. Did the switcheroo and it works now.
Thanks man.
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?
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 🙁
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?@Peter – search for
nofollow_the_category
instead (without the()
). It’s at the bottom there.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.
oops, can’t post the code in the echo. Basically it is a meta-robots-noindex tag.
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.
Thank you I will check into that. 🙂
Thanks a lot! I realized that many famous seo blog don’t use tags. However, I can see you use tags without “nofollow” in your post page, can you give me some info about that?
thank u but i wonder something i heart that the next link and previous link is better for seo becasue google wants to like breadcrumbs for explore between page is it a contradiction
lol I like that image! great idea for makerintg. Im subscribing
I just wanted to say thank you for taking the time to put it together and sharing it!
Thank for this script