• Resolved Vizou

    (@vizou)


    In a previous thread, I thought the problem was solved but it is not. For the record, I have turned plugins off and on, hard-flushed cache, etc., without luck. Luckily, the site is not yet “public”.

    I have a custom theme with ONE menu registered in a custom plugin like this (it was working perfectly prior to upgrade) :

    register_nav_menu( 'header-menu', 'Header Menu' );

    It was called like this in the theme :

    <nav>
    	<?php	wp_nav_menu(array(
    		'menu'            => 'Main menu',
    		'theme-location'  => 'header-menu',
    		'items_wrap'      => '<ul><li>%3$s</li></ul>',
    		'depth'           => 1
    		 ));
    	?>
    </nav>

    Since upgrading, WordPress is ignoring the location and menu name, both of which show up in Appearance / Menus perfectly and are assigned to one another.

    I have tried every possible variation but if I specify the location, NO menu shows up at all (the PHP is not parsed when looking at source). If I specify only items_wrap and depth, the menu outputs as the fallback pages (wrapped and proper depth).

    I cannot get the real menu to be recognized.

    I have tried creating a NEW menu in admin and specifying it. No go. I’m kind of panicking as many of my clients may be tempted to upgrade and omg what could happen!

    Any new insights?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Vizou

    (@vizou)

    Okay, so a few more experiments…

    I changed the functions.php (in my case plugin) to register TWO menu locations like so :

    register_nav_menus( array(
    	//menu location and pretty location name
    	'menu-1' => 'Primary menu',
    	'menu-2' => 'Secondary menu'
    ));

    Then I called the menu like this :

    <nav>
    	<?php wp_nav_menu(array(
    	'menu' => 'Main menu',
    	'theme-location' => 'menu-1',
    	'items_wrap' => '<ul><li>%3$s</li></ul>',
    	'depth' => 1
    	));
    	?>
    </nav>

    Result : The index page is using the “fallback” menu (wp_page_menu) with incorrect content (view source content to see this), BUT if you click on “calendar” for example, WordPress then uses the specified menu and location! (again, look at source code to see different menu).

    I cannot figure out what is happening. It seems like a BUG to me!

    The URL is here : http://norahrendell.com/nr/

    Thread Starter Vizou

    (@vizou)

    I’m posting my own temporary resolution after receiving zero responses here in the past day. It’s a partial solution, because it may have created another issue for me. In my custom functions plugin I had the following code so that I could use category templates to get a custom post type and custom taxonomies :

    ///////////////////////////////////////////////////////
    //get custom post types, too
    add_filter( 'pre_get_posts', 'my_get_posts' );
    
    function my_get_posts( $query ) { //this should be the query you use
    	if ( is_home() && false == $query->query_vars['suppress_filters'] )
    		$query->set( 'post_type', array( 'post', 'page', 'product', 'attachment' ) );
    	return $query;
    }

    This worked for me pre WP 4.0 but broke the home page menu (it would go to the fallback menu no matter what I specified). Removing this fixed the menus but not sure what will happen to my category template options…

    I am not going to mark this resolved until I see what happens there, in case anybody else is having this issue.

    Thread Starter Vizou

    (@vizou)

    …final post I hope, and a resolution.

    I found this function code from this thread (thanks!!!)
    http://wordpress.org/support/topic/wp_nav_menu-not-working-on-homepage?replies=5

    ///////////////////////////////////////////////////////
    //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');

    That fixed my problem as far as I can tell!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Custom menus are still broken in WP 4; location/menu name being ignored’ is closed to new replies.