How to include the ‘current-menu-ancestor’ class on a custom post type menu in WordPress?

This is the final working code: <?php function additional_active_item_classes($classes = array(), $menu_item = false){ global $wp_query; if(in_array(‘current-menu-item’, $menu_item->classes)){ $classes[] = ‘current-menu-item’; } if ( $menu_item->post_name == ‘product’ && is_post_type_archive(‘product’) ) { $classes[] = ‘current-menu-item’; } if ( $menu_item->post_name == ‘product’ && is_singular(‘product’) ) { $classes[] = ‘current-menu-item’; } return $classes; } add_filter( ‘nav_menu_css_class’, ‘additional_active_item_classes’, 10, … Read more

Any walker causes blank menu?

You need to make sure your menu is properly registered in your functions.php and then activated in the WP Dashboard. add_action( ‘init’, register_nav_menu( ‘navigation’, __( ‘Navigation’ ) ) ); Otherwise I was just facing a long list of empty bullet points. http://codex.wordpress.org/Navigation_Menus

Custom Nav Walker menu – Display category count

I think you should probably use wp_list_categories(), which even has parameters for a count, like e.g. show_count and pad_counts. Additionally it supports custom walkers via the walker parameter, but the walker would be based on Walker_Category – source -, which gives you every additional styling option you want.

Bootstrap dropdown nav pills not working with wp_nav_menu()

I ran into similar problem when I created a bootstrap navigation menu and dropdown links were all showing up at once. I used the following steps to correct the issue: download navwalker from github repo link: https://github.com/wp-bootstrap/wp-bootstrap-navwalker put this file in the root folder of the theme and in the functions.php file userequire_once get_template_directory() . … Read more

Highlighting current item of custom post types’ sub pages, listed by wp_list_pages

The problem with this code is that the query is being altered and current_page_item is being lost. This is the part causing problems. $post = get_post( $getid ); setup_postdata( $post ); If you comment out those two lines you’ll see that current_page_item appears. There are also some secondary problems with this code that have no … Read more

Menu Disappears on Category Pages

I know this is an old question but seems that is still unresolved. As @Milo said you may have an incorrect pre_get_posts implementation. Most people do this like this (example): add_filter( ‘pre_get_posts’, ‘query_post_type’ ); function query_post_type( $query ) { if ( is_category() ) { $post_type = get_query_var( ‘post_type’ ); if ( $post_type ) { $post_type … Read more

Menu items (all menus) being deleted randomly on their own [duplicate]

Here are two loggers to help you to tackle the problem. 1) If you want to know when the number of nav menu items changes, you can use the following logger: /** * A logger for nav menu items count – writes to the nav.log file. * * @link http://wordpress.stackexchange.com/a/149394/26350 */ add_filter( ‘wp_get_nav_menu_items’, function( $items, … Read more

Why is my menu order not working with wp_nav_menu?

AFAIK there’s a non-documented orderby parameter, that can be set to menu_order. Edit: Straight from core, inside /wp-includes/nav-menu-template.php Line# 195 (WP 3.3.1): $sorted_menu_items = array(); foreach ( (array) $menu_items as $key => $menu_item ) $sorted_menu_items[$menu_item->menu_order] = $menu_item; It’s the lines immediately before the Walker runs. So the set menu_order should affect the order. You’ll just … Read more