How to Create Anchor Links in WordPress Without Plugins

Add anchor links in WordPress to help visitors jump to sections on the same page or another page, using the block editor and simple HTML IDs.

Last updated:

Reviewed for accuracy by Jesse Nickles

Add an anchor to a heading

  1. Edit the WordPress post or page that contains the section you want to link to.
  2. Select the Heading block for that section. Add one if needed.
  3. Open the block settings sidebar using the Settings button if it is hidden, then expand Advanced.
  4. Enter a short identifier, such as shipping-info, in the HTML Anchor field. Do not include the # symbol.
  5. Save or update the page.

The HTML Anchor field sets the destination heading's HTML id. Each ID must be unique on its page, cannot contain spaces, and is case-sensitive. Start with a letter and use lowercase words separated by hyphens, such as shipping-info. WordPress also supports underscores, periods, and colons.

You can also create anchors on other WordPress blocks that provide an HTML Anchor field under Advanced. The Heading block is usually the most useful destination, but it is not the only option.

Create a link to that heading

  1. Highlight the text you want readers to click, such as Jump to shipping information.
  2. Choose the link button in the block toolbar.
  3. Enter #shipping-info as the destination and apply the link.
  4. Save the page and test the link on the published page.

The destination Heading block contains shipping-info in its HTML Anchor field; the clickable text links to #shipping-info. The # tells the browser to jump to that ID on the current page, and the name must match exactly, including capitalization.

Make a simple table of contents

For a long tutorial, add HTML anchors to its main headings, then place a list of links near the beginning of the page. If you have headings with the anchors overview and common-questions, a basic table of contents looks like this:

<ul>
  <li><a href="#overview">Overview</a></li>
  <li><a href="#common-questions">Common questions</a></li>
</ul>

You do not need to write this HTML in the block editor. Add a List block, enter the section names as list items, and link each item to its heading's # anchor using the usual link control.

Link to an anchor on another page

For a section on the current page, use #shipping-info. For another page on the same site, use the path /faq/#shipping-info. A full URL is useful when sharing the link externally or linking from a different website:

https://example.com/faq/#shipping-info

These links work in posts, navigation menus, and messages as long as the destination page has an element with the matching ID.

For a classic-theme menu, go to Appearance → Menus, open Custom Links, enter the destination URL ending in #shipping-info and the menu label, click Add to Menu, then Save Menu.

For a block theme, go to Appearance → Editor → Navigation, open the menu you want to edit, add a Custom Link item, enter its label and URL with the anchor, and save the navigation changes. Check the live header afterward. A menu created in the Site Editor must be used by the site's Navigation block to appear on the page; see the WordPress Site Editor navigation instructions.

Use HTML when you need more control

You can add anchor links directly in HTML with an id on the destination element and a link pointing to it. The block editor handles this for you too.

<h2 id="shipping-info">Shipping information</h2>
<a href="#shipping-info">Jump to shipping information</a>

Use a Custom HTML block if you need to insert raw HTML in the WordPress editor. Do not paste HTML tags into an ordinary paragraph expecting them to become markup.

When an anchor link does not work

If a sticky header covers anchored H2–H4 headings, scroll-margin-top can leave space above the destination when the browser jumps. The 6rem below is an example, not a universal offset; adjust it to the actual header height:

h2[id], h3[id], h4[id] { scroll-margin-top: 6rem; }