Skip to content

Instantly share code, notes, and snippets.

@billerickson
Created October 30, 2011 00:54
Show Gist options
  • Save billerickson/1325314 to your computer and use it in GitHub Desktop.
Save billerickson/1325314 to your computer and use it in GitHub Desktop.
Add rel=nofollow to categories
<?php
/**
* Add rel=nofollow to wp_list_categories
* @link http://www.billerickson.net/adding-nofollow-to-category-links/
* @author Bill Erickson
*/
function add_nofollow( $text ) {
$text = stripslashes($text);
$text = preg_replace_callback('|<a (.+?)>|i', 'wp_rel_nofollow_callback', $text);
return $text;
}
add_filter( 'wp_list_categories', 'add_nofollow' );
/**
* Add rel=nofollow to the_category
* @link http://www.billerickson.net/adding-nofollow-to-category-links/
* @author Bill Erickson
*/
function add_nofollow_cat( $text ) {
$text = str_replace('rel="category tag"', "", $text);
$text = add_nofollow($text);
return $text;
}
add_filter( 'the_category', 'add_nofollow_cat' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment