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.
2 Answers
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.– user2716Commented Jan 25, 2011 at 12:00
-
2@Zmey: You can disable
echo
forwp_list_pages()
, give the output towp_rel_nofollow()
, and echo the result of that. Commented Jan 25, 2011 at 12:12 -
@Zmey - If you've found a solution with the information provided, please be sure to mark this as the correct answer.– t31osCommented Jan 26, 2011 at 14:06
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');