How to get the navigation menu items? [closed]

To get a full control of the menu items you can create a custom Walker class, which extends the default Walker_Nav_Menu class. Override and customize the class methods as needed. Finally pass an instance of the custom walker to wp_nav_menu( array $args = array() ) with walker key in the $args array. If you only … Read more

Hide product categories if empty by leaving them positioned in the same place in the menu

I think with your question to hide the empty product categories in menu, we can add extra class for this menu item then adding CSS to hide these specific items. This code will add extra class hidden to empty product categories add_filter(‘nav_menu_css_class’, function($classes, $menu_item, $args, $depth){ if(‘taxonomy’ == $menu_item->type){ $term_id = $menu_item->object_id; $term = get_term($term_id, … Read more

How to highlight blog page menu item for blog posts?

To ensure the “Journal” menu item is highlighted for single posts without adding individual posts as sub-items in the menu, you can use a WordPress filter and some custom CSS or JavaScript. Here’s a solution that involves adding a bit of PHP to your theme’s functions.php file to modify the menu classes. Step 1: Add … Read more

How to Customize the Admin Sidebar Menu in WordPress Multisite Network by changing the backend code of the wp-admin code files?

Firstly, you should absolutely not modify core files. Ever. Any changes you make to core files can and will be overwritten any time WordPress updates. There are umpteen ways in which WP has been written to allow you to change its behaviour without hacking on core files: hooks, filters, APIs. Use those instead. In this … Read more

Primary menu item is not highlighting when page is active even though it is linked from a url with query string to pre-populate a form field

I checked both of your links and in the <body> tag, both of them have class page-id-1508, meaning that the page id is recognised correctly either with or without the query variable. However, as @mmm suggested in the comment above, it seems that you added the menu item as Custom Link (note the menu item … Read more

Managing menus in “The Store” theme [closed]

You have the same menu assigned to both locations. In order to decouple them you need to deselect “menu-principal” from the Top Menu location. It’s possible the theme may try to automatically populate a location when no menu is assigned. If this is the case, create a new menu with no items and assign it.

Only display nav menu if it is populated with menu items?

This solution was shared by @TheDeadMedic over here… $menu_exists_and_has_items = wp_nav_menu( array( ‘theme_location’ => ‘example-menu-location’, ‘container_class’ => ‘example-menu-container’, ‘menu_class’ => ‘example-menu-class’, ‘fallback_cb’ => false, ‘echo’ => false ) ); if ( $menu_exists_and_has_items ) { … Importantly, note that the menu is not echoed in the initial array saved to PHP variable…

How do I have WordPress use the tag for generated menus?

If you’re just trying to replace <ul…> and </ul> with <menu…> and </menu> in the generated HTML, you can use the wp_nav_menu filter: add_filter( ‘wp_nav_menu’, ‘wpse_426932_menu_fix’ ); /** * Fixes the menu HTML to use <menu> instead of <ul>. * * @param string $html The menu HTML. * @return string The fixed menu HTML. */ … Read more

In WordPress, I want to use code to filter out one menu item (page) from displaying when I call wp_nav_menu() function

That’s not the filter to use, instead use the wp_nav_menu_objects filter documented at: https://developer.wordpress.org/reference/hooks/wp_nav_menu_objects/ The docs contain a helpful code example provided by a contributor at the bottom, which I’ve modified slightly: function wpse_unset_menu_items( $menu_objects, $args ) { // remove this if you want it on all menus not just a specific menu aka primary_menu: … Read more