WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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...


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>
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
up vote 2 down vote accepted



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

Your Answer


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.