I've moved! I've moved my online home to mikejolley.com, and thats where I'll be blogging primarily. This site will stay live for archive purposes :)

WordPress Snippet #1: “nofollow” your blogroll

August 28, 2009 | Published in: Wordpress & plugins | Tags: , , , , 8

snippet

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!

Related Entries

8 Responses to “WordPress Snippet #1: “nofollow” your blogroll”

RSS feed for comments on this post.

  1. 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

  2. Mike Jolley says:

    @Erdem Calik: It encoded my > it will work now.

    Comment made on August 30, 2009 at 1:10 pm

  3. Ketel Blog says:

    Thanks…!!!

    I need this…

    Comment made on March 13, 2010 at 9:37 am

  4. John burry says:

    Thanks, for website and for text :)

    Comment made on June 12, 2010 at 5:38 pm

  5. 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

  6. Peter says:

    Great script – thanks!

    Comment made on August 14, 2010 at 10:19 pm

  7. 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

  8. micx51 says:

    Thanks! Verry helpfull, as is the downloads plugin!

    Comment made on October 4, 2010 at 9:26 pm

The comments are closed.

About this site

Blue Anvil is the online web design journal & portfolio of , a web designer from Norfolk, England. Read More »
MiniCard Theme for WordPress
  • Featured work - More

    • Beefjack
    • Integrity
    • theotaku.com
  • Latest Tweet - More

    • Hunt for old TV stand 2 hours. Loft - no. Spare room - no. Downstairs - no. Give up. Collapse on bed. Its under the bed o_0 #fail
  • Out of the blue - More

    • Download Monitor 3.3.5 Tagged for release

      The latest update to Download Monitor for WordPress has been released; this version comes with a many fixes and some new features, such as improved sorting. For full details view the readme; you can grab the plugin here.

    • Closing the Forums

      Just posting to let current users know that I’m closing the forum on Blue-Anvil. This is mainly due to spam-registrations getting out of hand and being a general nuisance. I will be posting good topics as FAQ items within posts if applicable.

      Please note that you can still post and get help for my plugins/themes by posting on the wordpress.org website.

    • Show off your MiniCard!

      Are you a user of the WordPress MiniCard theme? Its been downloaded over 14,000 times so far!

      If you have used it as-is, made your own child-theme or done something creative with it, please show off your MiniCard’s in the comments, I’d love to see how the theme is being used!

    • Spam Stopper updated for WordPress 3.0

      My Spam Stopper plugin has been updated for WordPress 3.0 (version 3.1.3) – you can grab it here. Sorry this update took longer than my other plugins but this one gets less lovin’ – if you want to change that feel free to donate, spread the word, or rate it on the WordPress.org plugin page.