• So it appears that 4.0 has destroyed my main nav-bar menu. For some reason it only shows a single option on the nav bar and it happens to be to a page that was deleted some time ago. (not sure why it picked that page). So there is literally no way to navigate my site right now. I purchased a Theme so it’s been a bit difficult to track down the nav bar in but this is what I have found so far.

    In the header.php file I came across this….

    [ Moderator note: Code fixed, please wrap code in backticks or use the code button. ]

    $defaults = array(
    'theme_location' => '',
    'menu' => '',
    'container' => 'div',
    'container_class' => '',
    'container_id' => '',
    'menu_class' => 'nav navbar-nav top-menu-inset',
    'echo' => true,
    'fallback_cb' => 'wp_page_menu',
    'before' => '',
    'after' => '',
    'link_before' => '',
    'link_after' => '',
    'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s',
    'depth' => 0,
    'walker' => new Bootstrap_Walker()
    );
    
    wp_nav_menu( $defaults );
    
    ?>

    On this theme I am not even sure where to start to track down this issue. If anyone can give any assistance at all – you would be a life and site saver.

Viewing 7 replies - 1 through 7 (of 7 total)
  • I also experienced this; WP was using the “fallback” menu (wp_page_menu) and ignoring my custom menu.

    If your theme uses custom post types, you might check the functions.php file in that theme as my menus broke when my code to support custom post types was not correctly written (apparently). View these 2 threads :

    https://www.ads-software.com/support/topic/wp_nav_menu-not-working-on-homepage?replies=5

    https://www.ads-software.com/support/topic/custom-menus-are-still-broken-in-wp-4-locationmenu-name-being-ignored?replies=4#post-5977314

    And here is the code I am now using to support querying custom post types (your post type may have a different name; mine was “products” so I added that).

    //include custom post types in queries
    function include_post_types( $query ) {
    
    	if ( !is_preview() && !is_singular() && !is_admin() ) {
        	$post_types = array('post', 'page', 'product' );
    
    		// Only do this if the post type is not already set
    		$existing_post_type = $query->query_vars['post_type'];
    		if ( empty( $existing_post_type ) ) {
    
    			$query->set( 'post_type' , $post_types );
    
    		}
    	}
    
    	return $query;
    }
    add_filter('pre_get_posts' , 'include_post_types');
    Thread Starter HYLMN

    (@hylmn)

    The closest I can come to finding some ref like this is below. I have about tried everything I can think of at this point…. So frustrated with this.

    function add_videos_post_types_to_loop( $query ) {
    
    	if( is_category() || is_tag() && empty( $query->query_vars['suppress_filters'] ) ) {
    
    		$query->set( 'post_type', array('post', 'nav_menu_item', 'videos'));
    
    	return $query;}

    Can you post a URL to the site? You need to look at the source code to see whether your “fallback” menu is being shown or your custom menu. Also, if you have not emptied your Trash, the page may still show up…

    I’d be happy to look at the site if you like.

    Have you checked Appearance > Menus to see if you can re-set the correct menu to the correct location?

    This happened to a site of mine upon upgrading to 4.0, and that was all I had to do.

    Thread Starter HYLMN

    (@hylmn)

    Thank you guys for ringing in on this. I found the quickest and least aggravating way to fix the problem! I rolled WordPress back to the previous version for now so my live site wont be down for days on end. I am going to have to set up a localhost site to run the upgrade and figure this thing out. I most likely will have to cut the theme into pieces to figure out how it was written so I can account for the new release of wordpress and their changes.

    Thank you again for reaching our and trying to lend a helping hand. And if nothing else, it was relieving to know I was not the only one having the issue!

    So again, thank you for the help!!!! Have a great weekend, hopefully without WP issues to deal with. ??

    You need to add the id, slug, or name of the menu in your array parameters. So 'menu' => 'Name of your Menu' would be one way to solve it. This way you would not have to roll back to the previous version of WordPress.

    I posted an answer to this on a similar thread at https://www.ads-software.com/support/topic/wp-40-broke-main-menu?replies=25

    To recap the details here:

    Issue:
    Occurs when original code has missing or incorrect parameters for wp_nav_menu. When wp_nav_menu calls failed in the past (before WP 4.0), it defaulted to the first menu that was created. Now in 4.0, there is a sort on the menus by name on line 280 of wp-includes/nav-menu-template.php triggered when $menu returns false from bad, or no parameters. This means it will now default to the first menu alphabetically.

    The problem:
    If the menu call in question is not properly passing menu parameters through an array in your templates, or you’re passing a broken array or string it will now default to a different menu, assuming you have more than one menu in your WP site, and the title names were not added in alphabetical order.

    The fix:
    Verify the argument arrays you send to wp_nav_menu do not contain any trailing characters, extra commas, incorrect parameters, etc. In this particular case, you could add the name of the menu you created in Appearacne -> Menus as the ‘menu’ parameter and it should resolve the issue.

    vanjwilson

    (@vanjwilson)

    I had a client with a custom theme that someone had coded before I got on the project, and the theme developer had coded registering the menus as:

    $menus = array(
    		'top-header-menu' => 'Top Header Menu',
    		'header-menu' => 'Header Menu',
    		'footer-menu' => 'Footer Menu'
    );
    register_nav_menus($menus);

    After we updated to WordPress 4.0, the footer menu was showing up as the main navigation, as well as in the footer.

    After some troubleshooting, I found that the slug in the database’s wp_terms table had been changed to main_menu for the menu with that ID number.

    So, I changed the call to the main nav in header.php from

    wp_nav_menu(array('menu' => 'Header Menu', ...

    to

    wp_nav_menu(array('menu' => 'main-menu', ...

    and that fixed the issue.

    (I also updated the menu registering code in functions.php to use the new name/slug.

    I suspect WordPress automatically changing the slug was in the changelog somewhere, but this thread is one of the top results in Google for this problem, so I wanted to share this fix here.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘4.0 Upgrade busted my main nav menu’ is closed to new replies.