• nmilner

    (@nmilner)


    Hello,

    I’d like to change the primary menu (both full screen and mobile burger) within a plugin and not having much luck with the code snippets found on the web. What I am finding is that I can change full sreen menu but the theme layout is ignored and the burger menu is empty when in moble view.

    I have a filter

    $this->loader->wp_add_filter('wp_nav_menu', array(
                $this->loader,
                'select_plugin_nav_menu'
            ), '10', '2');
    

    which calls

    
    public function select_plugin_nav_menu($html, $args)
        {
         if ($args->theme_location == THEME_NAV_MENU_LOCATION) {
             wp_nav_menu(array(
                        'menu' => $menu_to_show,
                        'menu_class' => 'nav-menu'
                    ));
         }
         return $html;
    }
    

    Please could you advise how I can correctly change the primary menu within php?

    Thanks

Viewing 5 replies - 1 through 5 (of 5 total)
  • Leo

    (@leohsiang)

    Hi there,

    Not sure if I fully understand.

    Can you link me to the page in question?

    Also, have you checked with the plugin’s support team first?

    Let me know ??

    Thread Starter nmilner

    (@nmilner)

    Sorry, I haven’t really explained what I am doing very well.

    I have a plugin that I wrote which changes the primary menu based on the wordpress page and the code above is what is in my plugin. It has worked fine until I used it with the GeneratePress theme.

    I have been researching and I tried also using this to change the primary menu set in the theme but now I get no menus at all :/

    I have a number of Menus defined in the wordpress site and all I’m trying to do is change the menu used by GeneratePress as the primary menu based on the page that is is being displayed. I guess I’m going down the wrong track with the snippets I have used and therefore I’d be grateful if you could tell me the correct me to have my plugin change the menu used for the primary menu in GeneratePress based on the page that has loaded.

    David

    (@diggeddy)

    Hi there,

    i would use the wp_nav_menu_args filter to switch the menu arg.
    See here for an example:

    https://generatepress.com/forums/topic/how-to-replace-the-primary-menu-for-logged-in-users/#post-2438959

    Thread Starter nmilner

    (@nmilner)

    @diggeddy : thank you ever so much – exactly what I needed ??

    David

    (@diggeddy)

    Glad to be of help

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Change the Pimary menu using php’ is closed to new replies.