Support » Themes and Templates » How to add an automatically created page to navigation menu

  • Hi,

    I have created a few pages automatically( by using a function to create pages) and assigned them their respective page templates.Now I want one of the pages to appear in the navigation menu.How can I do it wothout going into the dashboard menu option?I want that when the page is created automatically it should automatically appear in the navigation menu but only one particular page not all.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Make sure <?php wp_nav_menu(); ?> is included in your header.php file, after creating a page it will automatically appear within the menu..

    When you don’t want a page to appear in the menu, you can simply get its ID ( example #12 ) and exclude it like this:

    <?php wp_nav_menu('exclude=ID'); ?>

    Or add something like this block of code below, instead of wp_nav_menu(); so as to include all menu items in single page/s ( providing their IDs in the place of 1,2,3 ) and exclude some pages ( provide their IDs in the 4th line in the place of IDs_here ) if the view is out of your desired pages :

    <?php if( is_single( array( 1, 2, 3 ) ) ) {
        wp_nav_menu();
    } else {
        wp_nav_menu('exclude=IDs_here');
    }
    ?>

    I am bad at explaining lol so hopefully you get the point

    Thread Starter mitua

    (@mitua)

    I will come this after a few hours.First let me correct the footer problem.And u are very good at explaining and thats why I told that u made it easier for me.So take that thing out of your mind.

    Thread Starter mitua

    (@mitua)

    Ok.Now let us discuss on this issue.and lets go step by step.

    The wp_nav_menu is there in my theme’s header and initially it created just aa ‘sample’ page.However i didn’t find anywher where this ‘sample’ is in my header.php.

    Now coming to the point ,as you told whenever a page is created it automatically appears in the navigation menu but it is not happening in my case.I have also read the same in other posts.But for me none of the pages which are being created automatically are getting on the navigation menu.
    Also I have changed the permalink from default to postname.So what ever u mention keep in mind that thing.

    For the time being I just want my ‘contact’ page along with the index page to come to the navigation menu and no other page without going to the dashboard’s menu option.

    Thread Starter mitua

    (@mitua)

    In the menu settings,
    we have the option:
    Auto add pages: ‘box’: Automatically add new top-level pages to this menu

    The box was not ticked so no pages were appearing automatically.so what I am going to do is initially when I dont want the pages to be on the navigation menu I will untick the auto add pages off and then when I want any page in the navigation menu I will tick that on.hehehehe.What a solution.you can give your comments over this.Also you can mention how to exclude the pages if I have changed the permalinks to postname as you have shown for ids.For the time being this issue is also resolved.so only one last issue is left so whenvever you find the time today you can go through that.

    That’s a good solution. And as to exclude page/s from the menu, you don’t need to update permalink structure all you need is to insert ‘exclude=1,2,3’ [pages IDs] into wp_nav_menu() . I already use that and it is working..

    Thread Starter mitua

    (@mitua)

    My permalink is already in postname and have kept as post name only.Right now its not required to exclude the pages this way.However if its required then i will ask u further how to do that if page ids are with postname.

    Now my last issue is there for the time being .Its a bit complicated it seems but am sure You will be able to help me in that too and make it easier for me.I am pasting the link here or else you can find the link in my profile activities:

    https://wordpress.org/support/topic/frontend-editing-not-working?replies=1

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘How to add an automatically created page to navigation menu’ is closed to new replies.