wp_nav_menu not appearing for a couple pages

I solved the problem with the page, the correct answer is ptriek’s comment below.

Well I’m having a bit of an odd problem here, wp_nav_menu works on all pages EXCEPT my category pages (probably my archive page too but there’s no links on the website to the archive pages so that’s alright).

Read More

Although there is archive.php in my theme files, this controls what is displayed on category, tag, archive, author, etc. pages.

I just don’t understand why, since every page uses the same header.php to display wp_nav_menu, it won’t show up for the category pages.

Am I overlooking something? I’ve been banging my head against my keyboard trying to figure this out and it just won’t work!

Using a very simple code: <?php wp_nav_menu('container_class=menu-header&theme_location=primary'); ?>

Related posts

Leave a Reply

4 comments

  1. I had the same problem, but with a newer version of WordPress (3.7.1).

    On pages with custom taxonomies of custom posts, the wp_nav_menu was not shown. The solution below worked for me.

    in functions.php of the theme:

    add_action( 'pre_get_posts', 'my_pre_get_posts' );
    function my_pre_get_posts($query) {
      if ($query->get('post_type') === 'nav_menu_item') {
        $query->set('tax_query','');
      }
    }
    
  2. Implode’s answer is right and helped me a lot. I tried to implement a hook (pre_get_posts) for avoiding to display posts of subcategories. My hook worked well despite of no more Nav-Menus.

    So, when change the tax_query you have to avoid doing this for the query with post_type == 'nav_menu_item'.

  3. Answer by Implode solve issue only if you are not using other queries like ‘meta_key’ even . I found complete solution here.

    function fix_nav_menu( $query ) {
        if ( $query->get( 'post_type' ) === 'nav_menu_item' ) {
            $query->set( 'tax_query', '' );
            $query->set( 'meta_key', '' );
            $query->set( 'orderby', '' );
        }
    }
    
    add_action( 'pre_get_posts', 'fix_nav_menu' );
    
  4. This one works for me. The answer found in this link on the second last post/comment: https://wordpress.org/support/topic/wp-nav-menu-dissapears-in-category-pages-1/?replies=15#post-1859168

    Just need to add this on the theme’s function.php file

    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('nav_menu_item','post','articles');
        $query->set('post_type',$post_type);
        return $query;
        }
    }