• Resolved pattydelicious

    (@pattydelicious)


    Wp_nav_menu(); calls my custom menu correctly on all pages except for the index. On the index it just lists whatever “Pages” I have created. Wp_nav_menu is written in my header.php file, so I’m not sure why it’s showing up differently on my index than any other page.

    If I switch themes (to one similar but without my modifications) the problem is corrected, so it’s somewhere in the theme I’m creating but I’m not sure where. Any ideas? Thank you.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Do you have a front-page.php in your theme?

    Or open every php file and search for the unwanted wp_list_pages(); function…

    Thread Starter pattydelicious

    (@pattydelicious)

    I have neither front-page.php nor wp_list_pages();

    Looking at the Codex for wp_nav_menu(); (https://codex.www.ads-software.com/Function_Reference/wp_nav_menu) I something about it falling back to wp_page_menu(); but I don’t understand how this works and how I messed it up with my changes to index.php.

    Hmm… can you show us your header.php and index.php (with https://www.pastebin.com)?

    Thread Starter pattydelicious

    (@pattydelicious)

    The problem you have is that you didn’t register the second menu. Go in to your functions.php file and look for something like the below. You’ll see that I have two menu’s there, which makes the whole thing work.

    add_theme_support( 'nav-menus' );
    	add_action( 'init', 'register_my_menus' );
    	function register_my_menus() {
    	register_nav_menus(
    	array(
    	'menu-1' => __( 'Navigation Menu' ),
    	'menu-2' => __( 'Meta navigation Menu' )
    		)
    Thread Starter pattydelicious

    (@pattydelicious)

    I actually used this code I found on the forums in my functions.php file and it works perfectly:

    add_filter('pre_get_posts', 'query_post_type');
    	function query_post_type($query) {
    			if(is_category() || is_tag() ) {
        				$post_type = get_query_var('post_type');
    						if($post_type)
    	    						$post_type = $post_type;
    						else
    	    						$post_type = array( 'post', 'video', 'image', 'audio' ,'nav_menu_item');
        					$query->set('post_type',$post_type);
    						return $query;
        			}
    		}
Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Wp_nav_menu(); ignores custom menu, displays posts’ is closed to new replies.