Skip to content

Instantly share code, notes, and snippets.

@seezee
Last active December 1, 2021 18:21
Show Gist options
  • Save seezee/8d622da451cb856e4f110272a705d355 to your computer and use it in GitHub Desktop.
Save seezee/8d622da451cb856e4f110272a705d355 to your computer and use it in GitHub Desktop.
Disabled WordPress Navigation Links
@seezee
Copy link
Author

seezee commented Jun 30, 2021

Disable "placeholder" links in WordPress navigation, while keeping semantics and ensuring accessibility. See this essay for background on the accessibility issues.

See this Pen for a working demonstration (vanilla JavaScript and jQuery).

Add the class .nolink to "container" menu items in Appearance > Menus.

You'll also want to style the cursor like this:

li.nolink>a {
  cursor: default;
}

@seezee
Copy link
Author

seezee commented Nov 17, 2021

Refactored the code from jQuery to vanilla JS (ES6).

@seezee
Copy link
Author

seezee commented Nov 23, 2021

Wrap code in functions. Fix bug where links that weren't direct children were also prevented from their default behavior. Target both the link and the span inside of the link.

@seezee
Copy link
Author

seezee commented Dec 1, 2021

Commented out matches.removeAttribute('href'); for keyboard accessibility.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment