- This topic has 12 replies, 3 voices, and was last updated 8 years ago by
Tom.
-
AuthorPosts
-
March 12, 2018 at 7:21 am #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!
March 12, 2018 at 8:35 am #517922Leo
StaffCustomer SupportHi there,
Did UberMenu provided you the code you need to add?
March 12, 2018 at 4:43 pm #518248Mary 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?March 12, 2018 at 8:43 pm #518323Tom
Lead DeveloperLead DeveloperWhat 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.
March 13, 2018 at 7:26 am #518850Mary 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.
March 13, 2018 at 5:18 pm #519267Mary 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.
March 13, 2018 at 5:46 pm #519276Tom
Lead DeveloperLead DeveloperSo 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?
March 13, 2018 at 6:04 pm #519297Mary 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.
March 13, 2018 at 7:44 pm #519337Tom
Lead DeveloperLead DeveloperYou 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.
March 14, 2018 at 5:18 pm #520233Mary Pearson
Thanks for your help Tom. I’ll close this topic now and will get further support from UberMenu.
March 14, 2018 at 9:52 pm #520330Tom
Lead DeveloperLead DeveloperNo problem! Hope they’re able to help 🙂
March 15, 2018 at 4:54 pm #521101Mary 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
March 16, 2018 at 12:28 am #521293Tom
Lead DeveloperLead DeveloperAwesome! What great support. Thanks for sharing it here 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.