Support » Fixing WordPress » nav_menu doesn't appear in homepage

  • Resolved adahhane


    I have a small problem with nav_menu that is not appear in my homepage after I created a new custom post types.

    This is code that i put it in my functions.php

    add_action('init', 'create_companies_type');
        function create_companies_type(){
        register_post_type('information', array(
         'label' => __('Nos informations'),
         'singular_label' => __('information'),
         'public' => true,
         'show_ui' => true,
         'capability_type' => 'post',
         'hierarchical' => false,
         'supports' => array('title', 'author', 'thumbnail','editor','custom-fields'),
    add_filter( 'pre_get_posts', 'my_get_posts' );
      function my_get_posts( $query ) {
      if ( is_home())
      $query->set( 'post_type', array( 'information','post') );
      return $query;

    If you can help me I’ll really grateful. Thanks

Viewing 15 replies - 1 through 15 (of 19 total)
  • any help please !!


    Do you mean that the posts cannot be added to a custom manu, if so just add a new argument:

    'show_in_nav_menus' => true,



    Thanks Mr for your quickly answer,
    it’s not a solution of my problem
    I try it but it doesn’t work


    You have to create a custom menu,
    Go to Appearance > Menu, and see if the custom posts types are there, if they are create a menu and add them, then assign the menu to the template location.

    If you are not familiar with Custom Menu’s then have a look at the screenshot, create a new menu [ + ], add the menu items, assign it to a template location.

    Screenshot the custom posts are ‘Information Posts’ and been added to the custom menu!

    I’m sorry if my problem not very explicit so,
    I’ve do some screenshot to explain it better.

    In HomePage: The nav_menu dosen’t appear !
    In Other Page: it’s work perfectly

    Thanks man for your answers

    Look at the source code of the homepage (from the browser) and see if the nav menu code (all menus) are there. If it is there, then we know it is related with the css/html. Sometimes that happens when leaving a open div or the nav menu doesn’t have enough space for an extra menu (perhaps your new custom post type).

    Hello thanks for you answer,
    So, I looked in my code source and I think that all are correctly done.

    for homepage :

    for headerPage :

    for functions.php :

    I was afraid you were going to look at the source code on your files so I updated my post but probably too late.

    While looking at the home page on your browser, mouse right click and click on “view page source”. that is where you should look to see if all menus are there. You can gthub that source code for us to take a look too.

    Ok, Thanks.
    Menu isn’t appear in the source code

    source code

    Looking at the header.php code you have a lot of unclosed tags, as Hfort has said it looks like bad HTML with unclosed tags!

    No closing tag </div>

    <div id="catmenucontainer" class="auto-style2">

    Images are not closed:

    <img alt="" class="" longdesc="" src="">

    Should be closed:

    <img alt="" class="" longdesc="" src="" />
    <img alt="" class="" longdesc="" src=""></img>

    Also do you have two header files one without the menu?



    Hello, david
    Thanks man for your response.
    but the closing tag for </div> to close catmenucontainer div exists.
    for <img> if you looked them carfully you can understand that juste a commentaire with <!– –>.
    so, I don’t think that problem is caused by the bad HTML.

    Thanks a lot for your answer.

    Okay, then your post type code is causing conflicts with the nav menu.
    Replace your custom post type with this: and see if it works.

    I don’t think that problem is caused by the bad HTML

    View Source Code, copy it and paste it into the validator and you get 74 errors, with unclosed tags!

    Is the home page calling the same header file, the nav menu call has no conditional code in header.php, which may mean a different header file for the homepage?





    Hi david, yes he will have to take care of those code errors too. However, I noticed that in the source code, the Nav menu is empty.

    <div id="catmenu" class="menu-menu-container"><ul id="menu-menu" class="menu">????</ul></div>

    That means, it hasn’t be processed. My guess is that the filter “add_filter( ‘pre_get_posts’, ‘my_get_posts’ );” is conflicting with the nav menu. I don’t see the need of that filter. Just register the custom post type as usual and query the post type directly into the home template.

    @hfort : The same problem
    I think it comes from this function to dispaly the new post type:
    because once I disable it the menu appears in homePage

    @david : I’ll do what are you suggesting to me thanks.

Viewing 15 replies - 1 through 15 (of 19 total)
  • The topic ‘nav_menu doesn't appear in homepage’ is closed to new replies.