Currently I am working on a wordpress website, but I stumbled upon a little problem.
I am using wp_page_menu
to make a navbar to get to my other pages. Now it directs me to www.mysite.com/sport
, but I need it to direct me to www.mysite.com/sport#header
or www.mysite.com/sport/#header
.
Does anyone know how I can do this?
I tried using different plugins, or changing the slug or permalink, but this didn’t give me the result I wanted.
Thanks for helping guys!
Ok. Here is your code. I just override default walker of wordpress. Please focus on text #header in this code.
If you worry about this code. So you can go to file: …wp-includes/post-template.php at line 1238. It same code but I have add #header after get_permalink().
Hope that help.
Updated:
The second way:
Thanks Mere Development. I thinks this is same idea with him but it much more simple in your case. Like this:
Christian’s answer is great, and it got me thinking about alternative ways to do this, especially ones that allow you to use your
wp_page_menu()
function as originally requested. So here’s another approach using a filter.Add this function before your
wp_page_menu()
call, or in functions.phpThen use your wp_page_menu call as you were originally in your theme:
Explanation: It finds every href attribute of every link in the output of
wp_list_pages
and adds ‘#header’ to the end.wp_page_menu
in turn useswp_list_pages
to create output.