Gudlyf’s World

January 19, 2005

Filed under: Techie — Gudlyf @ 11:40 am

I’m not going to bother posting this as a downloadable plugin because it’s not worth it, but here’s a simple Wordpress plugin you can use to add Google’s “nofollow” relative attribute to all links within comments:


< ?php
/*
Plugin Name: NoFollow
Plugin URI: http://www.gudlyf.com/archives/2005/01/19/wordpress-plugin-nofollow/
Description: Adds the "nofollow" relative attribute to links left in comments (See http://www.google.com/googleblog/2005/01/preventing-comment-spam.html)
Version: 1.0
Author: Keith McDuffee
Author URI: http://www.gudlyf.com
*/

function nofollow($text) {

        $text = preg_replace('/<a /i','<a rel="nofollow" ',$text);
        return $text;
}

add_filter('comment_text', 'nofollow');
?>

I also recommend editing the comment_author_link() and comment_author_url_link() functions in the wp-includes/template-functions-comment.php file to read:


function comment_author_link() {
        global $comment;
        $url = apply_filters('comment_url', $comment->comment_author_url);
        $author = apply_filters('comment_author', $comment->comment_author);
        if (!$author) $author = 'Anonymous';

        if (empty($url)) :
                echo $author;
        else:
                echo "<a href='$url' rel='external' rel=’nofollow’>$author</a>”;
        endif;
}
function comment_author_url_link($linktext=”, $before=”, $after=”) {
        global $comment;
        $url = apply_filters(’comment_url’, $comment->comment_author_url);

        if ((!empty($url)) && ($url != ‘http://’) && ($url != ‘http://url’)) {
        $display = ($linktext != ”) ? $linktext : stripslashes($url);
                echo “$before<a href=’$url’ rel=’external’ rel=’nofollow’>$display</a>$after”;
        }
}

5 Comments »

  1. CAPTCHA and the anti-URL code, now that’s protection!

    Comment by TDavid — January 19, 2005 @ 3:14 pm

  2. Keith, there is an error in the code of this plugin - the first line “< ?php” shouldn’t have a space between the “<” and the “?” so it should be “

    Hope this helps,

    Keep up the good work,

    Tom

    Comment by Tom Raftery — January 20, 2005 @ 5:54 am

  3. I’ll try again!

    Keith, there is an error in the code of this plugin - the first line shouldn’t have a space between the “<” and the “?”. Anyone who copyies and pastes this code will have problems unless they realise the error is there and remove the space.

    Hope this helps,

    Keep up the good work,

    Tom

    Comment by Tom Raftery — January 20, 2005 @ 5:59 am

  4. Last time,

    Everytime I try to post this comment, it gets truncated because I’m putting in snippets of the code from the plugin above!

    This time no code - there is an error in the code of this plugin - the first line shouldn’t have a space in it.

    Anyone who copyies and pastes this code will have problems unless they realise the error is there, and remove the space.

    Hope this helps,

    Keep up the good work Keith,

    Tom

    Comment by Tom Raftery — January 20, 2005 @ 6:05 am

  5. Once again, thanks for the great plug in. Got Trackback wacked this morning and made some fixes for that but the use of this plugin will atleast prevent the dirty SOB’s from gaining their objective.

    Comment by MichaelE — February 1, 2005 @ 6:02 am

RSS feed for comments on this post. TrackBack URI

Leave a comment

Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

(required)

(required)


 
January 2005
S M T W T F S
« Dec   Feb »
 1
2345678
9101112131415
16171819202122
23242526272829
3031  

Subscribe!
Subscribe with Feedburner


follow Gudlyf at http://twitter.com

-5, Troll

Site Meter

Creative Commons License
This work is licensed under a Creative Commons License.