0

I'm using Divi by ET. I created a custom plugin with the following code to enable separate menus for logged-in and logged-out users.

function my_wp_nav_menu_args( Array $args = [] )
{
    if ( is_user_logged_in() )
        $args['menu'] = 'logged-in';
    else
        $args['menu'] = 'logged-out';

    return $args;
}

add_filter( 'wp_nav_menu_args', 'my_wp_nav_menu_args' );

The problem is that Divi now applies this custom menu setting to all menus. I've been trying to disable or at least modify the secondary header but am unable to do so.

The footer menu doesn't display by default if nothing is selected, but if I do select any option then the plugin overrides that setting and displays the 'logged-in'/'logged-out' menus only.

0

Please note, specific support questions to third party themes are off topic, so I will treat this in a general way, you should be able to implement this with your current theme

To make your code work on only one menu, you need to target that specific menu only. To do that, you will need to check the current menu item location, and if it mathches a given value, then make your changes. The theme lacation is stored as $args['theme_location']

You can try the following: (Just get the correct menu and change accordingly in the code below)

add_filter( 'wp_nav_menu_args', 'my_wp_nav_menu_args', 999 );
function my_wp_nav_menu_args( $args )
{
    if ( 'MENU LOCATION' == $args['theme_location'] ) {
        if( is_user_logged_in() ) { 
            $args['menu'] = 'logged-in';
        } else {
            $args['menu'] = 'logged-out';
        }
    }
    return $args;
}
  • My pleasure, glad it works. Enjoy :-) – Pieter Goosen Jul 29 '15 at 9:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.