WordPress Snippet #1: “nofollow” your blogroll

The Wordress Snippets series of posts will give you some useful code snippets for use in your projects – just copy and paste (but try to understand how they work!).
This snippet will add rel="nofollow" to the links in your blogroll, or those outputted by wp_list_bookmarks. Add to functions.php or your links template.
1 2 3 4 5 6 7 8 | function nofollow_my_bookmarks( $links ) { foreach($links as $link) { $link->link_rel .= ' nofollow'; $link->link_rel = trim($link->link_rel); } return $links; } add_filter('get_bookmarks', 'nofollow_my_bookmarks'); |
How it works
WordPress uses a function called get_bookmarks when it gets links for your blogroll – we use a filter to hook in and add the ‘nofollow’ rel tag.
Found this post useful? Why not buy me a coffee!










Erdem Calik says:
Hello;
I put this code to functions.php but,i get error S:
Comment made on August 30, 2009 at 3:27 am
Mike Jolley says:
@Erdem Calik: It encoded my > it will work now.
Comment made on August 30, 2009 at 1:10 pm
Ketel Blog says:
Thanks…!!!
I need this…
Comment made on March 13, 2010 at 9:37 am
John burry says:
Thanks, for website and for text
Comment made on June 12, 2010 at 5:38 pm
Tod says:
Strange, but nor working. It find’s blogroll links, but third line of your come do nothing, all rel values remains the same as they was.
Comment made on July 19, 2010 at 10:41 pm
Peter says:
Great script – thanks!
Comment made on August 14, 2010 at 10:19 pm
muusa says:
wow its really a nice work … can you please tell me how to remove that image option in my blog.. or tell me how to put some image in it.. its blank and looking very bad .. i cant remove it and neither cant enter a image or some thing in it
chamoo,s blog
help me out please
Comment made on September 1, 2010 at 11:53 am
micx51 says:
Thanks! Verry helpfull, as is the downloads plugin!
Comment made on October 4, 2010 at 9:26 pm