Walker for anchors on subpages
-
I’m trying to create a webpage where the menu links to main pages, with chilpages as sub sections on the given page, and hence I would like the main menu item to link to the page, but any sub link to an anchor. Much like I have done with a terrible jQuery hack on this website;
$(‘ul.sub-menu > li’).each(function( e ){
subpage = $(this).find(‘a’).attr(‘class’);
parent = $(this).parent().parent().find(‘a’).attr(‘href’);url = parent + ‘#’ + subpage;
$(this).find(‘a’).attr( ‘href’, url );console.log( parent + ‘#’ + subpage );
});The biggest problem with this hack is the anchor is now a post ID, not the slug. I can change this, but I feel like there should be a much better and more solid way of doing this with a walker.. Any input would be highly appreciated!
- The topic ‘Walker for anchors on subpages’ is closed to new replies.