Mark menu item as current-menu-item for category

I use this functions. First of all, you have to add some custom class to your menu item (allow class input in Screen options, it’s not visible by default). function mark_menu_item_as_active($classes, $item) { if( in_array(‘my-custom-class’,$classes) && ( is_category(‘my-category’) /* OR …*/ ) ) { $classes[] = ‘current-menu-item’; } return $classes; } add_filter(‘nav_menu_css_class’, ‘mark_menu_item_as_active’, 10, 2); … Read more

Add a class to the body tag when a menu is enabled

Use the has_nav_menu to detect if the menu is configure in a body_class filter. Something like add_filter( ‘body_class’, ‘wpse209469_body_class’ ); function wpse209469_body_class( $classes ) { if (has_nav_menu(‘primary-menu’)) $classes[] = ‘primary-menu’; return $classes; } If you have two menus you can change the condition to match both, or just do two filters. There is probably a … Read more

Get number of root elements in walker class

I’m not sure if this is what you’re after. You can use $this to reference the current walker instance. class YPE_custom_navwalker extends Walker_Nav_Menu { public function start_lvl(&$output, $depth=0, $args=array()) { $items = wp_get_nav_menu_items( $args->menu->term_id ); echo $this->get_number_of_root_elements( $items ); parent::start_lvl(&$output, $depth,$args); } }

Top Menu showing as Plain text before page load [closed]

You have to revise and reorder your code structure. Your site loads 27 render-blocking javascript files and 33 CSS files before the content above the fold. Also you load some plugin content before the styles are applied. Try to defer the blocking CSS and JS. Load everything early that is needed to display the first … Read more

Menu Item Location

The wp_nav_menu_items filter has a secondary parameter that it passes: $args. What we need to do is set up our filter to accept second args by passing a priority 10 and the number of args 2: add_filter( ‘wp_nav_menu_items’, ‘my_counter_nav_menu’, 10, 2 ); Now that we’re passing args – if we peek into what it holds … Read more