How to highlight the right item in the navbar
The filter you need is nav_menu_css_classes. You should be able to test for *in_category* on single post and archive pages, and add the appropriate class there.
The filter you need is nav_menu_css_classes. You should be able to test for *in_category* on single post and archive pages, and add the appropriate class there.
You can try it this way. Now we are talking about pages you can set up a separate template for the page that needs a different menu. This where WordPress’s newer menu feature is really nice. First if you are using the newer menu feature of WordPress place this in place of your current menu: … Read more
You can filter the title of each nav menu item. Unfortunately, the filter is named ‘the_title’ – if we just add a simple filter for it, we may catch strings outside of nav menus too. So we need a second function to switch our nav menu title filter on when the menu class starts and … Read more
Each nav menu item is stored a post type named nav_menu_item. The horizontal position is stored in the column menu_order The vertical position (hierarchy) is stored as post meta field named _menu_item_menu_item_parent holding the parent nav_menu_item ID. To create nested lists WordPress looks for _menu_item_menu_item_parent on each item, and if there is an item with … Read more
Looking for a solution for the same problem, I came across this: add_filter( ‘nav_menu_css_class’, ‘add_parent_url_menu_class’, 10, 2 ); function add_parent_url_menu_class( $classes = array(), $item = false ) { // Get current URL $current_url = current_url(); // Get homepage URL $homepage_url = trailingslashit( get_bloginfo( ‘url’ ) ); // Exclude 404 and homepage if( is_404() or $item->url … Read more
If you want the options to be extensible by developers, just add a custom filter to the output: wp_nav_menu( apply_filters( ‘wpse119371_nav_menu_args’, array( ‘theme_location’ => ‘primary’, ‘container’ => false, // etc. ) ) ); Then, a developer merely has to add a filter callback: function wpse119371_filter_nav_menu_args( $args ) { // Modify $args $args[‘container’] => ‘div’; // … Read more
I have done a complete answer on this a while ago on SO. You can see the complete post here. For the sake of WPSE users, I have copied my answer from that post. I have not edited it, this post was originally about adding and displaying a nav menu to the footer, but the … Read more
As @toscho said, you can call the walker class with parameters as you did: new BEMwalker( ‘mobile’ ) The constructor of BEMwalker will take the arguments (like any other function or method in PHP) so you can access the parameter(s) via $this: class BEMwalker extends Walker_Nav_Menu { private $classes; public function __construct( $classes=”” ) { … Read more
Apparently custom nav menu walkers are not supported though they were supposed to be. I’m surprised this only has been discovered now. However, there is an easy fix for you to get them to work. Just add this to your theme: add_filter( ‘wp_nav_menu_args’, function( $args ) { if ( isset( $args[‘walker’] ) && is_string( $args[‘walker’] … Read more
Walker_Nav_Menu is the core class to handle navigation menus. You can use it to handle your navigation menu, or you can create your own children class that extends this class. If you decide to use your own class, then you must pass an instance as an argument when you use wp_nav_menu() class myWalkerClass Extends \Walker_Nav_Menu … Read more