[Support request] Different main menu for logged in users

Home Forums Support [Support request] Different main menu for logged in users

Home Forums Support Different main menu for logged in users

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1554087
    Michael

    Hello,
    I wish to use a different main menu for logged in users.

    adding this snippet works but it also changes my other navigation menus.

    add_filter( 'wp_nav_menu_args', function( $args ) {
            if ( is_user_logged_in() ) {
                $args['menu'] = 'Main2';
            } else {
                $args['menu'] = 'Main';
            }
        return $args;
    } );

    I’m trying to avoid using a plugin

    thanks!

    #1554999
    David
    Staff
    Customer Support

    Hi there,

    you can set a condition for the Theme Location , for example this would apply to the Primary Nav:

    add_filter( 'wp_nav_menu_args', function ( $args ) {
        if ( 'primary' === $args['theme_location'] ) {
            if ( is_user_logged_in() ) {
                $args['menu'] = 'Main2';
            } else {
                $args['menu'] = 'Main';
            }
        }
        return $args;
    } );
    #1555693
    Michael

    That did the trick! thanks, David.

    I also plan to do the same for the Off Canvas Menu. Could you tell me how to target that as well?

    #1556137
    David
    Staff
    Customer Support

    The off canvas panel has a theme location of: slideout so this condition:

    if ( 'primary' === $args['theme_location'] ) {

    becomes:

    if ( 'slideout' === $args['theme_location'] ) {

    #1556183
    Michael

    That worked. thanks!

    #1556271
    David
    Staff
    Customer Support

    Glad to be of help

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