New Landing How can we help? Themeforest Theme Support Dante Login Logout Menus

Viewing 15 posts - 1 through 15 (of 19 total)
  • Posted in: Dante
  • #141573
    jfarr
    Member
    Post count: 32

    I currently have two menus using the function below…

    function my_wp_nav_menu_args( $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' );

    Unfortunately it changes all the menus including my footer menu. How can I target it so that it only targets the main menu?

    Thanks in advance

    #141627
    Kyle – SUPPORT
    Moderator
    Post count: 35880

    Hi

    Not sure if this will work but please can you try:

    function my_wp_nav_menu_args( $args = '' ) {
    
    if( is_user_logged_in() ) { 
        $args['main_navigation'] = 'logged-in';
    } else { 
        $args['main_navigation'] = 'logged-out';
    } 
        return $args;
    }
    add_filter( 'wp_nav_menu_args', 'my_wp_nav_menu_args' );

    – Kyle

    #141775
    jfarr
    Member
    Post count: 32

    Unfortunately this did not work.

    #141779
    Kyle – SUPPORT
    Moderator
    Post count: 35880

    I will forward this to Rui to see if he knows how to do it

    – Kyle

    #141780
    jfarr
    Member
    Post count: 32

    If it helps I’ve been trying to use this article but none of the solutions work for Dante… http://www.wpbeginner.com/wp-themes/how-to-show-different-menus-to-logged-in-users-in-wordpress/

    #141915
    Mohammad – SUPPORT
    Moderator
    Post count: 27441

    Hi,
    Please try to use this code:-

    function my_wp_nav_menu_args( $args  ) {
    
     if( 'main-navigation' == $args['theme_location'] ) {
    
       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' );

    Hope that should work.

    Thanks
    Mohammad

    #142059
    jfarr
    Member
    Post count: 32
    This reply has been marked as private.
    #142076
    Rui Guerreiro – SUPPORT
    Keymaster
    Post count: 25779

    Hi,

    That code is a bit tricky because it affects all the menus.
    Other approach is to use other menu location for the logged in user.

    Are you using Top bar Menu? We could use that to solve this.
    In the Main navigation you would put the menu for visitors an in the Top Menu Location the menu for logged in users.

    After that I need to add some custom code.

    Let me know if it’s ok for you.

    -Rui

    #142485
    jfarr
    Member
    Post count: 32

    I would be fine heading down this direction as long as the top menu could be in the same spot as the main menu spot when it’s replaced.

    #142493
    Rui Guerreiro – SUPPORT
    Keymaster
    Post count: 25779

    Hi,

    In the file sf-header.php located in dante/includes/

    find this code

    
    $main_menu_args = array(
    				'echo'            => false,
    				'theme_location' => 'main_navigation',
    				'walker' => new sf_mega_menu_walker,
    				'fallback_cb' => '',
    				'menu' => $page_menu
    			);
    

    and replace by this one

    
    if( is_user_logged_in() ) { 
    			 
    			$main_menu_args = array(
    				'echo'            => false,
    				'theme_location' => 'main_navigation',
    				'walker' => new sf_mega_menu_walker,
    				'fallback_cb' => '',
    				'menu' => $page_menu
    			);
    			}else{
    			$main_menu_args = array(
    				'echo'            => false,
    				'theme_location' => 'top_bar_menu',
    				'walker' => new sf_mega_menu_walker,
    				'fallback_cb' => '',
    				'menu' => $page_menu  
    			);	
    				
    		}
    

    If the user is logged in he will see the menu associated to the Main Navigation location, but if he isn’t logged in he will see the menu associated to the Top Bar Menu Location.

    Let us know the result.

    -Rui

    #142501
    jfarr
    Member
    Post count: 32

    I have made the requested changes but nothing has happened. I have cleared my cache as well.

    #142631
    Rui Guerreiro – SUPPORT
    Keymaster
    Post count: 25779

    Hi,

    Strange it worked fine in my server.
    Can you provide me admin access to check the file changes?

    -Rui

    #142643
    Mohammad – SUPPORT
    Moderator
    Post count: 27441

    Hi,
    Please attach a marked screenshot of your issue as you posted in first. So i can see that where is coming Menu at header and footer?
    Thanks
    Mohammad

    #142742
    jfarr
    Member
    Post count: 32
    This reply has been marked as private.
    #142757
    Rui Guerreiro – SUPPORT
    Keymaster
    Post count: 25779
    This reply has been marked as private.
Viewing 15 posts - 1 through 15 (of 19 total)

You must be logged in and have valid license to reply to this topic.

License required for the following item
Login and Registration Log in · Register