How to add Custom Menu to some pages but not others

Hello,

On our site we have pages like this:

http://demo.e3ngage.com/dreams-home/
http://demo.e3ngage.com/dreams-business/

And you can see that they have different sub-menus. We had hired an outsourced developer to do this and I'm not sure how they did it, but now whenever I create a new page somewhere, there is no option (like the other pages listed above) to add this custom sub menu (in the Appearance > Menus area). Is there somethign I need to copy/paste from these pages the developer did to the new pages that do not have menu areas? Some of the affected pages include:

http://demo.e3ngage.com/custom-play-home-design-process-commercial/

http://demo.e3ngage.com/mountain-play-lodge/

http://demo.e3ngage.com/options

Thank you in advance for any help you can provide.

Regards,

AD

  • Patrick

    Hi again @Adrian

    I hope you are well today!

    Looking at the CSS in browser tools, you can see that the ul in those 2 menus have different classes that correspond to those 2 pages.

    This may be a feature of the theme you are using. Or it may have been custom coded in the theme's functions.php or header.php files.

    If it's not a theme feature, open those 2 files and look for instances of wp_nav_menu. You'll likely find whatever code the developer had added to create menus specific to those pages.

  • Adrian

    Hi Patrick, thanks for the great support! So i looked through both files and the only thing I found close to wp-nav-menu was in the functions file and was this:

    require_once(THEME_CLASSES . "/wp-nav-custom-walker.php");

    Im sorry but im not sure what to do now...

    I did find these CSS references that seem related to the menus:

    .main-navigation-ul li a {
    height:30px !important;
    line-height:30px !important;
    }
    .current-menu-item{
    border-top:3px solid #333;
    margin-top:-3px!important;
    }
    .current-menu-item a{
    color:#999;
    }
    .main_menu:nth-child(2){
    padding-top:0px!important;
    }
    .main-navigation-ul > li > a{
    padding-right: 18px!important;
    }
    .bx-viewport {
    height: 240px;
    margin-left: 3.5%!important;
    overflow: hidden;
    position: relative;
    width: 93%!important;
    }

    ...a few lines below this list of page-ids:

    #mk-page-id-7551, #mk-page-id-2561, #mk-page-id-7549, #mk-page-id-7547, #mk-page-id-7516, #mk-page-id-5234{
    display:none;

    Do you think these page ids are being told the css above and thus displaying the menus? Sorry for my ignorance, still learning i suppose.

  • Timothy Bowers

    Hey there.

    Looking at the CSS like mk-page-id-7551, this is targeting a page ID. The display:none is then hiding everything within that ID.

    Hard to know what the developer did exactly, if theres any PHP logic in there without studying all the code.

    So did he make this so each page would create it's own menu section that you could assign menus too?

    Or was it coded so that each time you add a parent item it shows at the top when on the active state (the page) it then shows it's child links?

    Is he not about so you could maybe just ask?

    You tease me with this site, everytime I see all those cool houses and castles I want one but then I'd have to get one for the kids too! lol :slight_smile:

    Take care.

  • Adrian

    Hey Tim, thank you for the follow up! Haha, yea these play houses are pretty ridiculous - client says he is in Pakistan selling one to some oil tycoon lol.

    To answer some of your questions, it seems that there are three menus in the Appearance > Menus editor that he added, one for all the subpages in the Dreams for the Home area, one for the subpages in the Dreams for your Business area, and one for the subpages in the Our Dreams area. We can then drag and drop of the pages into the menus.

    I've noticed that NEW pages do not have an area reserved for the child menus, making me think we have to put in a page id somewhere to associate it with the specific menu it needs.

    Do you think I would add the page ids for the new pages that we want these child menus on to the CSS stylesheet? I see a bunch of page ids in there. Or in the functions file, which I did not realyl see anything that reminded me of a page id or a nav menu area?

    Please let me know if you have any ideas on this.

    Kind regards,

    AD

  • Timothy Bowers

    Hmmm,

    Surely it would have been better to have just one menu and show child links of those menu items when it's parent is in an active state.

    I would imagine that being the best way to achieve what you're doing.

    Are you able to share the theme and all of it's code?

    I'm thinking it might just be easier for us to take a look and see if there is something quick we can advise without you needing to invest time in coding or hiring another developer.

    Cheers.

  • Timothy Bowers

    Hey Adrian.

    Wow there's a fair bit going on there. :slight_smile:

    It seems whoever did this is basically do a load of checks from the header.php file, it starts around line 716:

    /jupiter/framework/actions/header.php

    if ( !is_front_page() ){
        wp_nav_menu( array( 'theme_location' => 'pages-top','container' => 'nav',
    					'container_id' => 'mk-main-navigation',
    					'container_class' => 'main_menu',
    					'menu_class' => 'main-navigation-ul-custom',
    					'fallback_cb' => ''
    					 ));
    } 
    
    if ( is_front_page() ){
        wp_nav_menu( array( 'theme_location' => 'homepage-menu','container' => 'nav',
    					'container_id' => 'mk-main-navigation',
    					'container_class' => 'main_menu',
    					'menu_class' => 'main-navigation-ul',
    					'fallback_cb' => '',
    					'walker' => new rc_scm_walker ) );
    } 
    
    if( is_page('dreams-business')){
    	 wp_nav_menu( array( 'theme_location' => 'dreams-business',
    					'container' => 'nav',
    					'container_id' => 'mk-main-navigation',
    					'container_class' => 'main_menu',
    					'menu_class' => 'main-navigation-ul',
    					'fallback_cb' => '',
    					'walker' => new rc_scm_walker ) );
    }
    if( is_product_category('main-street-collection')){
    	 wp_nav_menu( array( 'theme_location' => 'dreams-business',
    					'container' => 'nav',
    					'container_id' => 'mk-main-navigation',
    					'container_class' => 'main_menu',
    					'menu_class' => 'main-navigation-ul',
    					'fallback_cb' => '',
    					'walker' => new rc_scm_walker ) );
    }
    
    if ($cat=='main-street-collection' && is_product()) {
     wp_nav_menu( array( 'theme_location' => 'dreams-business',
    					'container' => 'nav',
    					'container_id' => 'mk-main-navigation',
    					'container_class' => 'main_menu',
    					'menu_class' => 'main-navigation-ul',
    					'fallback_cb' => '',
    					'walker' => new rc_scm_walker) );
    }
    if( is_page('theming-facades-amenities')){
    	 wp_nav_menu( array( 'theme_location' => 'dreams-business',
    					'container' => 'nav',
    					'container_id' => 'mk-main-navigation',
    					'container_class' => 'main_menu',
    					'menu_class' => 'main-navigation-ul',
    					'fallback_cb' => '',
    					'walker' => new rc_scm_walker ) );
    }
    if( is_page('commercial-playhome-gallery')){
    	 wp_nav_menu( array( 'theme_location' => 'dreams-business',
    					'container' => 'nav',
    					'container_id' => 'mk-main-navigation',
    					'container_class' => 'main_menu',
    					'menu_class' => 'main-navigation-ul',
    					'fallback_cb' => '',
    					'walker' => new rc_scm_walker ) );
    }

    And goes on and on until around 1109.

    In the functions.php file you find the register_nav_menus function use in the supports() function around line 159.

    It seems to me that the top menu "Dreams for the home" and "Dreams for your business" are constant and the ones under them are really children.

    Well the menu feature in WordPress allows for parent and child so it seems crazy to me to have taken this approach. Also there are multiple checks for different pages before placing the same menu again. For example:

    if ($cat=='arched-windows' && is_product()) {
     wp_nav_menu( array( 'theme_location' => 'dreams-home',
    					'container' => 'nav',
    					'container_id' => 'mk-main-navigation',
    					'container_class' => 'main_menu',
    					'menu_class' => 'main-navigation-ul',
    					'fallback_cb' => '',
    					'walker' => new rc_scm_walker ) );
    }
    
    if ($cat=='window-accents' && is_product()) {
     wp_nav_menu( array( 'theme_location' => 'dreams-home',
    					'container' => 'nav',
    					'container_id' => 'mk-main-navigation',
    					'container_class' => 'main_menu',
    					'menu_class' => 'main-navigation-ul',
    					'fallback_cb' => '',
    					'walker' => new rc_scm_walker ) );
    }
    
    if ($cat=='operable-windows-trim' && is_product()) {
     wp_nav_menu( array( 'theme_location' => 'dreams-home',
    					'container' => 'nav',
    					'container_id' => 'mk-main-navigation',
    					'container_class' => 'main_menu',
    					'menu_class' => 'main-navigation-ul',
    					'fallback_cb' => '',
    					'walker' => new rc_scm_walker ) );
    }

    It's the same menu but we're checking like $cat=='operable-windows-trim'. Surely doing this once and running through an array would have been much better with far less code. I still wouldn't have though.

    I'd want to know why the developer took this path.

    If it were me personally then I'd start again, remove the menus and do it properly. It's not a huge job, but it's not a 2 minute thing either. It seems in some places the code is used twice and probably not needed.

    Here is an example:

    http://services.loudfeed.tv/2012/03/horizontal-sub-menu-wp-themes/

    The example is showing a horizontal menu with children.

    Anyway, if you continued the original route then you'd have add more to that long list to check for the specific page. That would be the least efficient but certainly quickest for now.

    Take care.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.