Hallo,
In my main menu, I want the links to link to e.g. ?page_id=2#main, so people don't have to see the top again, after clicking the link.
So I would like to know how to put a #main in thhe end of the href string.
Thank you for your time...
Hallo,
In my main menu, I want the links to link to e.g. ?page_id=2#main, so people don't have to see the top again, after clicking the link.
So I would like to know how to put a #main in thhe end of the href string.
Thank you for your time...
Put this in your theme's functions.php:
function main_in_link($wp_list_pages) {
$patterns = '/(\<li class="page_item[^>]*><a href=")(.*?)\"(.*?)<\/a\>/';
$replacements = '\1\2#main"\3</a>';
return preg_replace($patterns, $replacements, $wp_list_pages);
}
add_filter('wp_list_pages', 'main_in_link');
Now all links produced by wp_list_pages have #main in the url.
a hack:
instead of
<?php wp_list_pages('title_li='); ?>
you could try and use
<?php $pali = wp_list_pages('title_li=&echo=0'); echo str_replace('" title=','#main" title=',$pali); ?>
keep all your other paramters.
Use alchymyth solution. This way you have #main on the links for this particular wp_list_pages on your main menu.
@keesiemeijer
thanks for the filter solution as well, as it allows a more global approach, for instance if the pages list is in widgets where the code is not easily accessible.
Thanks guys, works perfect!
This topic has been closed to new replies.