- This topic has 13 replies, 3 voices, and was last updated 3 years, 11 months ago by Tom.
-
AuthorPosts
-
March 7, 2018 at 12:51 pm #514183xdaniel
Hi GP-Team,
I tried to install ubermenu by this tutorial: https://sevenspark.com/docs/ubermenu-3/theme-integration/generatepress using code snippets instead of a child theme. When I try to activate the snippet, I got the following error:
Cannot redeclare generate_navigation_position() (previously declared in /var/www/…/wp-content/themes/generatepress/inc/structure/navigation.php:20)
Does the snippet not work with newer versions of GeneratePress?
Best, Daniel
March 7, 2018 at 8:38 pm #514355TomLead DeveloperLead DeveloperThey need to update their code.
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 ); }
March 7, 2018 at 10:38 pm #514394xdanielYes Tom, that works! Thanks a lot. Hope your businness growth and you can keep this great support.
I’ll inform the guys from uber.
March 8, 2018 at 10:17 am #514944TomLead DeveloperLead DeveloperThank you! ๐
May 7, 2020 at 7:51 am #1273891DonThe site I’m working on will be needing a mega menu, which will be more complicated than the simple CSS solution provided by GP. I’m attempting to install UberMenu, and found that the UberMenu plugin doc still has the original old snippet code. I tried using your update, and snippets took the code request. However, when I try to activate the snippet, the activate button goes halfway with a question mark. Hovering on the button displays “An error occurred when attempting to activate”.
Any suggestions? Including looking at other Mega Menu plugins… I have tried Max Mega Menu, but ran into enough anomalies to want to check out other options. I’m even considering using the GP CSS version as a starting point and manually adding CSS extensions.
Thanks,
DonMay 7, 2020 at 11:35 am #1274256DonActually, UberMenu did update their doc and now has the same snippet cards as the ones you provided. However, when I try a “Save and Activate” from the snippet editor, the dialog displays:
The snippet has been deactivated due to an error on line 3:
Cannot redeclare function generate_navigation_position.Thanks,
DonMay 7, 2020 at 2:57 pm #1274540TomLead DeveloperLead DeveloperDid you try this code?: https://generatepress.com/forums/topic/ubermenu-and-generatepress/#post-514355
May 7, 2020 at 5:02 pm #1274636DonYes, I did use your update. To try and narrow the problem, I created a VM with the latest WP, GeneratePress (free version), Code Snippets and UberMenu. I can cut/paste the code using your reference and it still fails. Here’s a couple of screen shots:
https://drive.google.com/open?id=13sttIJet4xm-ZwH4-DxDoZbh8Twa1cAN
https://drive.google.com/open?id=1BUmqDUOHMP7pJuwdAU4ZFdYMs7whJfJq
I also scanned the website for files that contain the offending function, and got these two hits:
[root@jbm-web-centos8 ~]# grep -rlw -e “generate_navigation_position” /var/www/html
/var/www/html/wp-content/themes/generatepress/inc/customizer/helpers.php
/var/www/html/wp-content/themes/generatepress/inc/structure/navigation.phpI took a look at the modules, and didn’t see anything amiss, but I’m not competent with php.
Could this be a bug with Code Snippets?
Thanks,
DonMay 8, 2020 at 5:04 am #1275151DonI did a little more testing with different versions of PHP. I am running 7.4.4 on my dev system and 7.2.30 on the temporary VM I created for this test. Both are CentOS 7 images, and both have the same issue.
I’ve also posted on the Code Snippets support page and since the plugin is the component issuing the error.
Thanks,
DonMay 8, 2020 at 9:27 am #1275611TomLead DeveloperLead DeveloperHi Don,
Can you try using a child theme instead of the Code Snippets plugin?: https://docs.generatepress.com/article/using-child-theme/
May 8, 2020 at 9:50 am #1275667DonI installed the GP child theme on my test VM – not the development system I’ve been using for months. Too chicken at this point. I’ve also added the following to the child theme’s functions.php file:
/* Replace the theme's menu with UberMenu */ 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 ); }
I don’t see any errors when I access pages on the site. Is there an easy way to see if the ubermenu function has been installed correctly? Note: I don’t have an actual ubermenu license for this test vm…
Thanks,
DonMay 8, 2020 at 10:11 am #1275683DonBack to the Code Snippet error. I found this statement when looking at the php function_exists doc:
“function_exists will return false for functions disabled with the disable_functions ini directive. However those functions are still declared so trying to define them yourself will fail.”
Is is possible GP is issuing a disable_functions at some point?
Thanks,
DonMay 8, 2020 at 2:37 pm #1275970DonWith help from the UberMenu developer, I was able to verify that the child theme install method does work as intended.
Weird problem with Code Snippets.
Thanks
DonMay 8, 2020 at 3:52 pm #1276022TomLead DeveloperLead DeveloperGlad you got it working ๐
-
AuthorPosts
- You must be logged in to reply to this topic.