Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

How can I add a rel="nofollow" attribute to my category widget listings?

I'm currently filtering the call to wp_list_categories with this code in my functions.php...

function my_wp_list_categories($cat_args){
    $cat_args['title_li'] = '';
    $cat_args['exclude_tree'] = 1;\
    $cat_args['exclude'] = 1;
    $cat_args['use_desc_for_title'] = 0;
    return $cat_args;
    }
add_filter('widget_categories_args', 'my_wp_list_categories', 10, 2);

Update: When I try this...

add_filter('wp_list_categories','wp_rel_nofollow');

My links come out with escape slashes...

<li class=\"cat-item cat-item-5\">
  <a href=\"http://mysite/category/chinese-tea/\" title=\"View all...Chinese Tea\" rel=\"nofollow\">Chinese Tea</a>
</li>
share|improve this question
    
wrap your function in stripslashes() –  onetrickpony Jan 19 '11 at 23:49
    
Hey @maugly, for inline code, surround the code with backticks(left of the 1 key). –  t31os Jan 20 '11 at 13:55
    
@t31os Thanks. I did it now: $output = str_replace('href=', 'rel="nofollow" href=', $output); Could something like this be used as a filter?? I tested it and it seems to be working. I just dunno if it's a good practice. –  Michal Mau Jan 21 '11 at 10:54
add comment

1 Answer

up vote 2 down vote accepted

try:

add_filter('wp_list_categories','esc_wp_rel_nofollow');

function esc_wp_rel_nofollow($output){
   return   stripslashes(wp_rel_nofollow($output));
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.