How to Link to Page Content from a WordPress Navigation Menu

anchor | wordpress on-page links

Sometimes you might want your WordPress navigation menu items to link directly to a page section that sits in the middle of a larger page, rather than simply to the top of the page. For example: instead of creating a nav menu link to a Contact page, how do I create a menu link to the Contact section of my homepage?

Being able to create WordPress menu links to page sections is especially important on one-page websites, or on multi-page sites that have long scrolling homepages or sales pages. Either of these types of website might have, for example, “How it Works,” “Demo,” “Testimonials,” and “Buy Now” sections all on the same page.

To link to a page section, you’ll need to create a WordPress menu link to an anchor: a link embedded in your page content. Anchors are one of the web’s oldest technologies, and they still work great.

Fortunately, assigning an anchor to a page section, and then linking to that anchor from your WordPress navigation menu, is not tricky at all. This quick tutorial video shows you how.

And here’s a quick text summary of the information covered in the video:

How to Make WordPress Nav Menu Links to Page Sections

  1. Give the item you want to link to an id attribute—for example, <h2 id="target-element">Section Title</h2>. This id attribute is the element’s anchor.
  2. In the Menu area in either wp-admin or the Customizer, create a new Custom Link to add to your navigation menu.
  3. Set the Custom Link to point to the page on which the content lives, plus the # character, plus the value of the element’s id attribute—for example, https://mysite.com/about-us#target-element.
  4. Save your changes to the menu, and test the link from a few pages to make sure it works.

And that’s it! Creating WordPress menu links to page sections using anchors can be a very helpful way to orient your site’s visitors, so give it a try.


3 Responses

Comments

  • Martanian says:

    If you’ll add that kind of custom links to the main menu not as a child, but as the main menu link, then it can be highlighted as “active page”. So in the case that you described on your video, both “Test Page” and “Second section” links will be highlighted when you’ll open “Test Page”, which is not good in most cases.

    One of the possible solutions for that problem is to add custom CSS class for this kind of custom links, like “custom-link-no-highlight”, and then modify the theme CSS code (via child theme for example) to disable highlight for links with this class.

  • Manoj says:

    Great tutorial. I want to link a menu item to a certain part of a page & looking for the suitable guidance. I Googled and finally, I found this article.

    I never thought that the process was so simple.
    Thanks for the writing. It’s very useful.

    All the best,

  • Sondra says:

    Thank you for this tutorial. I’ve been searching for this and one that actually works. However I do have a question. After I create the custom link my header images on 4 of my 6 pages disappear. They only reappear after I remove the custom link.

    Have you ever come across this problem before and if so, do you have any advice for me in how to fix it and still retain my custom jump links.

Add a Comment

Your email address will not be published. Required fields are marked *