Fix Anchor Links not Working on Divi Mobile Sites

Written by Dan Mossop

Anchor links are a powerful tool for smooth navigation on a webpage. However, certain setups can cause issues, especially on mobile devices. A common problem is having multiple sections with the same anchor link ID on a Divi site, which can lead to anchor links functioning correctly on desktop but failing on mobile. Let's explore why this happens and how you can fix it.

Understanding the Problem

In HTML and CSS, each ID must be unique on a page. If you have multiple sections with the same ID (to accommodate different device views), browsers typically recognize only the first instance, leading to clickable anchor links on desktop but not on mobile.

Workarounds and Solutions

Combine Sections into One:

If the content in the two sections is not significantly different, combine them into one section:

  • Enable/Disable rows within that main section based on device size.
  • Keep the main section (with the anchor link ID) visible at all times.

This approach ensures the ID remains unique and functional across devices.

Minimize and Style the Desktop Section on Mobile:

If combining sections isn’t feasible due to substantial content differences, you can:

  • Keep the desktop section active on mobile but style it to minimize its presence:
  • Set its height to 1px and hide its rows on mobile.
  • Adjust margins and padding to reduce its vertical footprint.
  • Match its background color to adjacent sections for a seamless look.

This maintains the section’s presence for anchor linking while making it visually unobtrusive.

Separate IDs for Mobile and Desktop:

For a more device-specific approach:

  • Assign different CSS IDs to the mobile and desktop versions of the section.
  • Create device-specific buttons/links that target these different IDs.
  • Show/hide the appropriate buttons/links based on the device.

This method is more labor-intensive but can be effective for complex layouts.

Custom Code Solutions:

If none of the above solutions can be applied in your situation, it will probably be necessary to implement custom JavaScript to dynamically switch section IDs or modify link targets based on the device width.

This solution provides the most flexibility but requires a higher level of coding knowledge.

Supercharge Your Posts with AI-Generated CTAs

Boost your engagement and conversions with WP Magic CTAs. This plugin intelligently creates customized CTAs for each of your WordPress posts, helping guide your readers to the content they need. Perfect for enhancing your anchor link strategies and solving mobile navigation challenges.

About Dan Mossop

Dan is a Scottish-born web developer, now living in Brisbane with his wife and son. He has been sharing tips and helping users with Divi since 2014. He created Divi Booster, the first Divi plugin, and continues to develop it along with 20+ other Divi plugins. Dan has a PhD in Computer Science, a background in web security and likes a lot of stuff, 

0 Comments

Submit a Comment

Comments are manually moderated and approved at the time they are answered. A preview is shown while pending but may disappear if your are cookies cleared - don't worry though, the comment is still in the queue.

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

We may earn a commission when you visit links on our website.

Latest From Divi Booster

Enable Automatic Looping for YouTube Videos in the Divi Video Module

Enabling automatic looping for YouTube videos in your Divi video module ensures that content plays seamlessly and continuously without interruption. This feature can enhance user engagement, highlight key information, or create dynamic visual effects on your website....

Hide Video Controls in Divi Video Module

Disabling YouTube video controls in the Divi Video Module helps create a seamless, distraction-free viewing experience for your site visitors. This approach is useful when you want full control over how your video content appears and is interacted with on the page, or...

Mute YouTube Videos by Default in the Divi Video Module

In the Divi Video Module, starting your YouTube videos muted by default can create a more user-friendly browsing experience on your webpage. It is particularly beneficial for reducing distractions, enhancing visitor engagement, and providing a seamless content preview...

Autoplay Videos in Divi Video Module

Enabling videos in your Divi video module to start playing automatically can enhance both the site's design and user engagement. To ensure full compatibility with browser requirements, such as Chrome's autoplay policy, it's often necessary to start your videos muted...

How to Add the Post Status in Divi's Dynamic Content

Divi's Dynamic Content feature is great for enhancing your post/page templates with post-specific information. While Divi includes an option to show information such as the Post Created Date using Dynamic Content, there is no equivalent option for the Post Status....

Random Divi Posts