Skip to content

Instantly share code, notes, and snippets.

@eri-trabiccolo
Last active September 1, 2018 07:00
Show Gist options
  • Save eri-trabiccolo/0d94bfeb3e19fc5798b2 to your computer and use it in GitHub Desktop.
Save eri-trabiccolo/0d94bfeb3e19fc5798b2 to your computer and use it in GitHub Desktop.
Add rel nofollow to tags, author, date, thumbnails
add_filter('tc_display_post_thumbnail', 'strip_and_nofollow');
add_filter('tc_tag_list', 'strip_and_nofollow');
add_filter('tc_date_meta', 'strip_and_nofollow', 9999);
add_filter('tc_show_link_to_post_after_metas', 'strip_and_nofollow', 9999);
add_filter('tc_author_meta', 'strip_and_nofollow', 9999);
function strip_and_nofollow($text){
$text = stripslashes($text);
$text = preg_replace_callback('|<a (.+?)>|i', 'strip_and_nofollow_callback', $text);
return($text);
}
function strip_and_nofollow_callback($matches){
$text = $matches[1];
$text = str_replace(array(' rel="nofollow"', " rel='nofollow'"), '', $text);
$count = 0;
$text = preg_replace( array( '|(.+?rel=".+?)"|',"|(.+?rel='.+?)'|"), array('$1 nofollow"', "$1 nofollow'"), $text, 1, $count);
if ( ! $count )
$text .=' rel="nofollow"';
return '<a ' . $text . ' >';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment