1

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.

1
  • Hi. If you can accept your answer then that will help keep the site tidy. Thanks. Aug 10, 2016 at 8:42

1 Answer 1

1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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