0

I'd like to use the wp_list_pages as a navigation bar, but I don't want the links to be followed. This is the simple version of the code I'm using <?php wp_list_pages('hierarchical=1&title_li=&depth=1'); ?> but I have no idea how to add the "nofollow" to the links.

3

use wordpress build in funcion for that "wp_rel_nofollow" with a hook to wp_list_pages.

paste this code in your theme's functions.php file and you are set.

function add_no_follow($output){
  return wp_rel_nofollow($output);
}
add_filter('wp_list_pages', 'add_no_follow');

hope this helps.

  • I think this will nofollow all wp_list_pages links on my site. I'm using this code for different purposes (to list different groups of pages) and I don't want all of them no-followed, just the links in my nav-bar. – user2716 Jan 25 '11 at 12:00
  • 2
    @Zmey: You can disable echo for wp_list_pages(), give the output to wp_rel_nofollow(), and echo the result of that. – Jan Fabry Jan 25 '11 at 12:12
  • @Zmey - If you've found a solution with the information provided, please be sure to mark this as the correct answer. – t31os Jan 26 '11 at 14:06
0

paste this code in your theme's functions.php file.

function add_nofollow($text) {
    return str_replace('<a href=', '<a rel="nofollow" href=',  $text);    
}

add_filter('wp_list_pages', 'add_nofollow');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy