0

What wordpress hooks can be used to override how the primary menu is displayed in my wordpress header's navigation menu -- ideally in a way that will work cross-theme.

I need to build a wordpress website to have graceful fallback for visitors with javascript disabled. I can find plenty of themes whoose content is still visible without javascript, but I've failed to find a theme whoose hamburger menu is functional without javascript.

I'm now thinking the only solution is to adopt a very popular theme and just hack it so the hamburger menu works without javascript (there's plenty of examples of such menu implementations on the net).

But, rather than hacking one child theme, I think it would be more robust to make a plugin (since this problem is so widespread across most themes) so that the menu of whatever active theme can gracefully fallback (eg to a css menu) with <noscript>.

Which hooks should I override in a wordpress plugin to change the way that the primary navigation menu is displayed?

1
  • 2
    not all themes have a hamburger menu, and of those that do they use very different methods, you're going to need to be much more specific. There's nothing in WordPress itself that implements hamburger menus in a theme
    – Tom J Nowell
    Nov 29, 2023 at 20:30

1 Answer 1

0

Classic Themes

What wordpress hooks can be used to override how the primary menu is displayed in my wordpress header's navigation menu -- ideally in a way that will work cross-theme.

This isn't possible to do in a cross theme way, and there is nothing in WP that indicates if a hamburger menu is used, or APIs for implementing one. Each theme does its own thing.

You can filter nav menu markup but different themes display menus in different ways, in different places, with different styles. A lot of themes don't use the standard nav menu API directly to display their menus, especially those that implement more unusual menus such as hamburger or mega menus.

Detecting if a theme even has a hamburger menu to begin with isn't possible.

The best you can hope for is to replace all the HTML classes with your own, add your own styling, and hope it doesn't clash with the styling already in the theme. This will probably break the theme, and has no guarantee that it wouldn't be broken by styling.

In addition to that, different themes use different methods to implement hamburger menus, and there is no WordPress level support to disable or replace this as it isn't WordPress providing the hamburger menu.

So any plugin you write would need to have code for each and every specific theme you want to support, assuming those themes can be adjusted. You'll need to download and read through how each theme implements its hamburger menu.

Block Themes

Block themes however provide a much easier solution, create a plugin that adds a hamburger menu block, and tell users to use it in their theme.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.