Remove nofollow From WordPress Comments

Great little function to remove nofollow attribute from comments in wordpress. No need to use the dofollow plugin anymore, this is faster.

The code

Place the snippet bellow in your theme’s functions.php file.

function xwp_dofollow($str)
{
 $str = preg_replace(
 '~<a ([^>]*)\s*(["|\']{1}\w*)\s*nofollow([^>]*)>~U',
 '<a ${1}${2}${3}>', $str);
 return str_replace(array(' rel=""', " rel=''"), '', $str);
}

remove_filter('pre_comment_content',     'wp_rel_nofollow');
add_filter   ('get_comment_author_link', 'xwp_dofollow');
add_filter   ('post_comments_link',      'xwp_dofollow');
add_filter   ('comment_reply_link',      'xwp_dofollow');
add_filter   ('comment_text',            'xwp_dofollow');

Well done ! Try it yourself .

Leave a Reply

Your email address will not be published. Required fields are marked *