[Resolved] ubermenu and generatepress

Home Forums Support [Resolved] ubermenu and generatepress

Home Forums Support ubermenu and generatepress

  • This topic has 13 replies, 3 voices, and was last updated 1 year ago by Tom.
Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #514183
    xdaniel

    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

    GeneratePress 2.0.2
    GP Premium 1.5.6
    #514355
    Tom
    Lead Developer
    Lead Developer

    They 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 );
    }
    #514394
    xdaniel

    Yes Tom, that works! Thanks a lot. Hope your businness growth and you can keep this great support.

    https://celtic-rock.de

    I’ll inform the guys from uber.

    #514944
    Tom
    Lead Developer
    Lead Developer
    #1273891
    Don

    The 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,
    Don

    #1274256
    Don

    Actually, 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,
    Don

    #1274540
    Tom
    Lead Developer
    Lead Developer
    #1274636
    Don

    Yes, 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.php

    I 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,
    Don

    #1275151
    Don

    I 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.

    https://wordpress.org/support/topic/code-snippet-problem-with-ubermenu-install-in-generatepress/#post-12801998

    Thanks,
    Don

    #1275611
    Tom
    Lead Developer
    Lead Developer

    Hi Don,

    Can you try using a child theme instead of the Code Snippets plugin?: https://docs.generatepress.com/article/using-child-theme/

    #1275667
    Don

    I 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,
    Don

    #1275683
    Don

    Back 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,
    Don

    #1275970
    Don

    With 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
    Don

    #1276022
    Tom
    Lead Developer
    Lead Developer

    Glad you got it working ๐Ÿ™‚

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