Skip to content

Instantly share code, notes, and snippets.

@sowich
Last active September 1, 2018 07:56
Show Gist options
  • Save sowich/67e911e7d3bea466f087b8a50512351b to your computer and use it in GitHub Desktop.
Save sowich/67e911e7d3bea466f087b8a50512351b to your computer and use it in GitHub Desktop.
<?php
add_filter('wp_list_categories', 'esc_wp_rel_nofollow');
add_filter('wp_tag_cloud', 'esc_wp_rel_nofollow');
function esc_wp_rel_nofollow($output)
{
if (is_single() || is_category() || is_tag())
return stripslashes(wp_rel_nofollow($output));
return $output;
}
/*==================================================*/
add_filter('wp_list_categories', 'esc_wp_rel_nofollow');
add_filter('wp_tag_cloud', 'esc_wp_rel_nofollow');
function esc_wp_rel_nofollow($output)
{
//wp_reset_query(); #Вставить если не срабатывает is_single()
if (is_single() || is_category() || is_tag())
return preg_replace('#<a[^>+](.*)<\/a>#isU', '<a rel=\'nofollow\' $1</a>', $output);
return $output;
}
/*==================================================*/
add_filter('the_tags', function ($tags) {
if (!is_single())
$tags = preg_replace('#<a[^>+](.*)<\/a>#isU', '<a rel=\'nofollow\' $1</a>', $tags);
return str_replace(' rel="tag"', '', preg_replace('#<a[^>+](.*)>(.*)<\/a>#isU', '<a $1 title="$2">$2</a>', $tags));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment