Navigating a website smoothly is crucial for providing a good user experience, especially when using anchor links to jump between different sections of a page. However, one common issue arises when anchor links lead to sections that are obscured by fixed headers or sticky menus. This can lead to frustration for users, as the desired content may be hidden or cut off. Fortunately, WordPress offers several easy methods to fix this problem, allowing you to ensure that your anchor links work seamlessly.


Method 1:Adjust Scroll Behavior

You can use CSS to adjust the position slightly when the page scrolls to the section. To do this, you need to add a margin or padding to the target element in your HTML.

For example, you can modify your HTML like this:

how-to-fix-anchor-links-hidden-behind-fixed-header-method-1

The scroll-margin-top property tells the browser to stop scrolling 100px above the element, ensuring it won’t scroll too far down the page. You can adjust the value based on your needs.

Why You Use It?

  • HTML Context: The sentence needed to specify that you’re adding the scroll-margin-top property within the HTML tag of the element you’re targeting. This ensures readers understand that the adjustment isn’t just a CSS change but also requires them to edit the HTML.
  • Clarifying the Process: By emphasizing that the change involves HTML, it helps users who may not be familiar with how to implement such adjustments. This way, they clearly see that they need to locate the specific element in their HTML and modify it.
  • Avoiding Confusion: Without the clarification, users might mistakenly think that the adjustment could be made solely in a CSS file or block without needing to change the actual HTML content, leading to confusion.

Method 2: Use a Padding with an Empty Anchor Tag


You can add an empty anchor tag directly in the content editor:

  1. Edit Your Content:
    • Open the page or post where you need the anchor link to work.
  2. Insert an Empty Anchor:
    • Switch to the HTML view (or add a Custom HTML block if using the block editor) and insert an empty anchor tag above the target section:

html code

<a id=”heading-name”></a>

<p>Heading Name</p>

This approach places the anchor point above your content, allowing the browser to scroll to it without cutting off the text below the fixed header.

Why Use It?

  • This method provides a simple way to ensure that when users click an anchor link, the content appears correctly without being hidden by the fixed header. It can be easily implemented by content editors without needing CSS or JavaScript knowledge.

Fixing anchor links hidden behind fixed headers is essential for maintaining a smooth and user-friendly navigation experience on your WordPress site. Whether you choose to adjust scroll behavior with CSS, add padding with empty anchor tags, or apply custom CSS globally, each method provides a straightforward solution to ensure your content is easily accessible. By implementing these techniques, you can enhance user engagement and make it easier for visitors to find the information they need without frustration. Take these steps today to improve the usability of your site and create a more enjoyable browsing experience for your audience.

Read related article: How to Add Anchor Links in WordPress for Specific Sections