[Resolved] Ubermenu Restricted to one Sub-Domain

Home Forums Support [Resolved] Ubermenu Restricted to one Sub-Domain

Home Forums Support Ubermenu Restricted to one Sub-Domain

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #517863
    Mary Pearson

    I am trying to get UberMenu (Megamenu) to work on https://resources.christiangays.com. I see that I need to add some code to my functions.php but I don’t want it to take over all of my sub-domains. I just want it on the resources sub-domain.

    I also see from the forums that the code given on the sevensparks website is wrong.

    Could you please give me the code I need to make UberMenu work, but just on the resources sub-domain.

    Many thanks!

    GeneratePress 2.0.2
    GP Premium 1.5.6
    #517922
    Leo
    Staff
    Customer Support

    Hi there,

    Did UberMenu provided you the code you need to add?

    #518248
    Mary Pearson

    They provided code but I assume it will affect all domains.

    Tom says (on the forum) that the code on their website is wrong. It should be this:

    if ( ! function_exists( 'generate_navigation_position' ) ) {
        function generate_navigation_position(){
            if( function_exists( 'ubermenu' ) ){
                ubermenu( 'main' , array( 'theme_location' => 'primary' ) );
            }
        }
    }
     
    /* Stop the theme from filtering the menu output */
    add_action( 'wp_head' , 'stop_generatepress_menu_filter' );
    function stop_generatepress_menu_filter(){
        remove_filter( 'walker_nav_menu_start_el', 'generate_nav_dropdown', 10, 4 );
    }
    

    When I add this to functions I lose my Primary Menu, even if I change “primary” to “secondary” which is what I want it to replace.
    How do I adapt that so that it only works on Resources sub-domain?

    #518323
    Tom
    Lead Developer
    Lead Developer

    What is the resources sub-domain? A separate WordPress install?

    That code is correct, it will replace the primary navigation (in GP) with the UberMenu navigation.

    #518850
    Mary Pearson

    My main website is christiangays.com. I have several sub-domains of resources.christiangays.com, chat.christiangays.com, dating.christiangays.com, etc. They all use the same functions.php in child-theme.

    I only want to use UberMenu on the Resources domain name, so the code for functions.php must be restricted to that sub-domain. I do not want to use UberMenu on chat.christiangays.com or dating.christiangays.com etc.

    What do I need to change in that code to restrict UberMenu to resources.christiangays.com?

    Thank you.

    #519267
    Mary Pearson

    Yes indeed that code does replace the primary navigation on my main domain and all of my sub-domains. I do NOT want that. What I am trying to accomplish is

    1. Restrict UberMenu to ONLY the Resources sub-domain. All other sub-domains need to use GP menus.

    2. Replace the secondary menu, not the primary menu on Resources. I tried replacing “secondary” for “primary” in the code but it still removed the primary menu, not the secondary menu.

    #519276
    Tom
    Lead Developer
    Lead Developer

    So I assume those sub-domains are just pages within the same site?

    Does UberMenu have to replace an existing menu? Or can it create a new menu?

    #519297
    Mary Pearson

    Yes exactly. Those sub-domains were just a way of dividing the website into different sections. The functions.php file affects everything.

    I’m not sure re replacing an existing menu or creating a new one. I have created a new menu within the menus section called UberMenu and was assigning it to Secondary menu position since that is the menu it would replace.

    I also tried adding it as a Slide-Out menu but nothing shows up, however that is without using any code in functions.php.

    I have to de-activate UberMenu to get things back to normal.

    #519337
    Tom
    Lead Developer
    Lead Developer

    You might need to ask them if it’s possible to either conditionally initiate their plugin, or create a fresh menu with it so you can insert it on certain pages using a conditional.

    #520233
    Mary Pearson

    Thanks for your help Tom. I’ll close this topic now and will get further support from UberMenu.

    #520330
    Tom
    Lead Developer
    Lead Developer

    No problem! Hope they’re able to help ๐Ÿ™‚

    #521101
    Mary Pearson

    I thought I would forward the fix for this just in case anyone else might need it in the future. This is from tech support at UberMenu

    1. Because you’re using multisite, we had to adjust the code slightly to make it only apply to the Resources site rather than all sites. I’ve made that change and that is working fine (the code only affects the Resources site now)

    2. The integration code in the guide is for the primary menu. I had never seen any secondary menu before with GeneratePress. I searched for quite a while in the GeneratePress theme files before discovering that this secondary menu is actually from a premium plugin that you have installed, not part of the main theme.

    3. The secondary menu (from the GeneratePress plugin) has a different function signature (naturally), which we would need to override in order to integrate with the secondary menu rather than the primary menu:

    See http://tinypic.com/r/5loqop/9

    4. This function is pluggable, but the problem is that because it is defined in a plugin (rather than the theme), we can’t override it in a child theme, because the plugin file loads first. So there isn’t a way to reliably override it, since plugin load order is not guaranteed by WordPress.

    5. So what I’ve done is tracked down where the plugin hooks into the theme, unhooked the theme’s menu, and hooked in UberMenu instead.

    Here’s the final customization code, which I’ve added in your child theme functions.php

    //Replace secondary GeneratePress nav with UberMenu
    if( function_exists( 'ubermenu' ) ){
      remove_action( 'generate_after_header', 'generate_add_secondary_navigation_after_header', 7 );
      add_action( 'generate_after_header', 'generate_add_secondary_navigation_after_header_ubermenu', 7 );
      function generate_add_secondary_navigation_after_header_ubermenu(){
        stop_generatepress_menu_filter();
        echo '<div class="grid-container">';
      	ubermenu( 'main' , array( 'theme_location' => 'secondary' ) );
        echo '</div>';
      }
    }
    /* Stop the theme from filtering the menu output */
    //add_action( 'wp_head' , 'stop_generatepress_menu_filter' );
    function stop_generatepress_menu_filter(){
        if( function_exists( 'ubermenu' ) ){
            remove_filter( 'walker_nav_menu_start_el', 'generate_nav_dropdown', 10, 4 );
        }
    }

    You should now see UberMenu only replacing the secondary menu on your Resources subdomain

    #521293
    Tom
    Lead Developer
    Lead Developer

    Awesome! What great support. Thanks for sharing it here ๐Ÿ™‚

Viewing 13 posts - 1 through 13 (of 13 total)
  • You must be logged in to reply to this topic.