Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a CPT archive page and I want to create a navigation menu which will jump to anchors in the form

<a name="post-slug" http="{the permalink goes here}>The CPT Title</a>

I have been able to create the anchors in the template file so that's not a problem

For the links themselves at the top of the page I could either create them manually or by using custom links in the WordPress menu system .... but there are a good few so what I would rather try to do is to create a regular menu in the WordPress menu system. The problem with this is that I would need to adjust it's output somehow to change the regular links

href = "http://mydomain.com/post-slug"

to something more like

href = "/#post-slug"

I am wondering is there any way I can adjust wp_nav_menu() to do this ... or is there any other technique that I could use

NB. For clarity here please note that I am not referring to anchors within the editor or anything to do with the editor, this is entirely to do with template files and the WordPress Menu System and I won't be using the editor at all in this instance.

share|improve this question
add comment

1 Answer

Got it --- needed to use a walker function. I used a slightly modified version of the one in this tutorial

The main thing I modified was changing

$attributes .= ! empty( $item->url ) ? ' href="' . esc_attr( $item->url) .'"' : '';

to

$attributes .= ' href="#' . esc_attr( basename(get_permalink()) ) .'"' ;

but I will probably refactor the whole thing

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.