WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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://example.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

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) .'"' : '';


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

but I will probably refactor the whole thing

share|improve this answer

Your Answer


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.