Navigation
This is archived content. Visit our new forum.

Tagged: 

  • Author
    Posts
  • #1208694

    leehart09
    Participant

    Is there any way of turning off the buddypress and bbpress icons in the navbar for users who are not logged in?

    I tried to turn it off by doing the following:

    Dashboard settings – Buddypress – Options – ‘Show the toolbar for logged out users’. I unticked this box, but it still appears when users are logged out.

    Thanks.

    #1208703

    Christopher
    Moderator

    Thanks for writing in! To assist you with this issue, we’ll first need you to provide us with your URL. This is to ensure that we can provide you with a tailored answer to your situation. Once you have provided us with your URL, we will be happy to assist you with everything.

    #1209580

    leehart09
    Participant
    This reply has been marked as private.
    #1209606

    leehart09
    Participant

    I provided my website in the private reply above.

    I mentioned that I had put some code I found on another answer on this forum into my functions.php file. It allowed me to remove the ‘Activate your page’ from the submenu, and add in a ‘log out’ link. However, the log out link is also present when you are logged out (not just when you are logged in). Here is the code I applied. Can we tweak it so the logout submenu does not appear when user is already logged out?

    I’ve attached the code to this post.

    #1209608

    leehart09
    Participant

    Actually, if we can hide the buddy press menu on the nav bar from people who are not logged in, that would be ideal. You can let me know if I should delete code from the above file accordingly.

    Thanks!

    #1209668

    Rad
    Moderator

    Hi there,

    Please add this code 🙂

    function x_buddypress_navbar_menu( $items, $args ) {
    
        if ( X_BUDDYPRESS_IS_ACTIVE && x_get_option( 'x_buddypress_header_menu_enable' ) == '1' ) {
    
          if ( bp_is_active( 'activity' ) ) {
            $logged_out_link = bp_get_activity_directory_permalink();
          } else if ( bp_is_active( 'groups' ) ) {
            $logged_out_link = bp_get_groups_directory_permalink();
          } else {
            $logged_out_link = bp_get_members_directory_permalink();
          }
    
          $top_level_link = ( is_user_logged_in() ) ? bp_loggedin_user_domain() : $logged_out_link;
          $submenu_items  = '';
    
          if ( bp_is_active( 'activity' ) ) {
            $submenu_items .= '<li class="menu-item menu-item-buddypress-navigation"><a href="' . bp_get_activity_directory_permalink() . '" class="cf"><i class="x-icon-thumbs-up" data-x-icon="" aria-hidden="true"></i> <span>' . x_get_option( 'x_buddypress_activity_title' ) . '</span></a></li>';
          }
    
          if ( bp_is_active( 'groups' ) ) {
            $submenu_items .= '<li class="menu-item menu-item-buddypress-navigation"><a href="' . bp_get_groups_directory_permalink() . '" class="cf"><i class="x-icon-sitemap" data-x-icon="" aria-hidden="true"></i> <span>' . x_get_option( 'x_buddypress_groups_title' ) . '</span></a></li>';
          }
    
          if ( is_multisite() && bp_is_active( 'blogs' ) ) {
            $submenu_items .= '<li class="menu-item menu-item-buddypress-navigation"><a href="' . bp_get_blogs_directory_permalink() . '" class="cf"><i class="x-icon-file" data-x-icon="" aria-hidden="true"></i> <span>' . x_get_option( 'x_buddypress_blogs_title' ) . '</span></a></li>';
          }
    
          $submenu_items .= '<li class="menu-item menu-item-buddypress-navigation"><a href="' . bp_get_members_directory_permalink() . '" class="cf"><i class="x-icon-male" data-x-icon="" aria-hidden="true"></i> <span>' . x_get_option( 'x_buddypress_members_title' ) . '</span></a></li>';
    
          if ( ! is_user_logged_in() ) {
            if ( bp_get_signup_allowed() ) {
              $submenu_items .= '<li class="menu-item menu-item-buddypress-navigation"><a href="' . bp_get_signup_page() . '" class="cf"><i class="x-icon-pencil" data-x-icon="" aria-hidden="true"></i> <span>' . x_get_option( 'x_buddypress_register_title' ) . '</span></a></li>';
              $submenu_items .= '<li class="menu-item menu-item-buddypress-navigation"><a href="' . bp_get_activation_page() . '" class="cf"><i class="x-icon-key" data-x-icon="" aria-hidden="true"></i> <span>' . x_get_option( 'x_buddypress_activate_title' ) . '</span></a></li>';
            }
            $submenu_items .= '<li class="menu-item menu-item-buddypress-navigation"><a href="' . wp_login_url() . '" class="cf"><i class="x-icon-sign-in" data-x-icon="" aria-hidden="true"></i> <span>' . __( 'Log in', '__x__' ) . '</span></a></li>';
          } else {
            $submenu_items .= '<li class="menu-item menu-item-buddypress-navigation"><a href="' . bp_loggedin_user_domain() . '" class="cf"><i class="x-icon-cog" data-x-icon="" aria-hidden="true"></i> <span>' . __( 'Profile', '__x__' ) . '</span></a></li>';
          }
    
          if ( $args->theme_location == 'primary' ) {
            
            if (  is_user_logged_in() ) {
            $items .= '<li class="menu-item current-menu-parent menu-item-has-children x-menu-item x-menu-item-buddypress">'
                      . '<a href="' . $top_level_link . '" class="x-btn-navbar-buddypress">'
                        . '<span><i class="x-icon-user" data-x-icon="" aria-hidden="true"></i><span class="x-hidden-desktop"> ' . __( 'Social', '__x__' ) . '</span></span>'
                      . '</a>'
                      . '<ul class="sub-menu">'
                        . $submenu_items
                      . '</ul>'
                    . '</li>';
             } else {
    
             $items .= '<li class="menu-item current-menu-parent menu-item-has-children x-menu-item x-menu-item-buddypress">'
                      . '<a href="' . wp_login_url() . '" class="x-btn-navbar-buddypress">'
                        . '<span><i class="x-icon-user" data-x-icon="" aria-hidden="true"></i><span class="x-hidden-desktop"> ' . __( 'Log in', '__x__' ) . '</span></span>'
                      . '</a>'
                    . '</li>';
    
             }
    
          }
        }
    
        return $items;
    
      }
      add_filter( 'wp_nav_menu_items', 'x_buddypress_navbar_menu', 9997, 2 );

    That should do it, cheers!

    #1209740

    leehart09
    Participant

    Thank you for the speedy reply! I’ll try that now – just before I do, can you clarify if I should add the code on top of the rest of the code I had input before, or do I remove the old code and exchange it for this?

    Thanks again!

    #1209873

    Paul R
    Moderator

    Hi,

    You need to replace the code in your functions.php

    Thanks

    #1209920

    leehart09
    Participant

    Hi again,

    I’ve replaced the code but I can’t see the logout sub-menu when I’m logged in…

    I notice that there is a different icon now in place of the buddy press person when you are logged out. If I wanted to change this to a different icon, how would I go about doing that?

    And thank you for your help! 🙂

    #1210837

    Lely
    Moderator

    Hi There,

    Please update the code to this to add the logout submenu when logged in.

    function x_buddypress_navbar_menu( $items, $args ) {
    
        if ( X_BUDDYPRESS_IS_ACTIVE && x_get_option( 'x_buddypress_header_menu_enable' ) == '1' ) {
    
          if ( bp_is_active( 'activity' ) ) {
            $logged_out_link = bp_get_activity_directory_permalink();
          } else if ( bp_is_active( 'groups' ) ) {
            $logged_out_link = bp_get_groups_directory_permalink();
          } else {
            $logged_out_link = bp_get_members_directory_permalink();
          }
    
          $top_level_link = ( is_user_logged_in() ) ? bp_loggedin_user_domain() : $logged_out_link;
          $submenu_items  = '';
    
          if ( bp_is_active( 'activity' ) ) {
            $submenu_items .= '<li class="menu-item menu-item-buddypress-navigation"><a href="' . bp_get_activity_directory_permalink() . '" class="cf"><i class="x-icon-thumbs-up" data-x-icon="" aria-hidden="true"></i> <span>' . x_get_option( 'x_buddypress_activity_title' ) . '</span></a></li>';
          }
    
          if ( bp_is_active( 'groups' ) ) {
            $submenu_items .= '<li class="menu-item menu-item-buddypress-navigation"><a href="' . bp_get_groups_directory_permalink() . '" class="cf"><i class="x-icon-sitemap" data-x-icon="" aria-hidden="true"></i> <span>' . x_get_option( 'x_buddypress_groups_title' ) . '</span></a></li>';
          }
    
          if ( is_multisite() && bp_is_active( 'blogs' ) ) {
            $submenu_items .= '<li class="menu-item menu-item-buddypress-navigation"><a href="' . bp_get_blogs_directory_permalink() . '" class="cf"><i class="x-icon-file" data-x-icon="" aria-hidden="true"></i> <span>' . x_get_option( 'x_buddypress_blogs_title' ) . '</span></a></li>';
          }
    
          $submenu_items .= '<li class="menu-item menu-item-buddypress-navigation"><a href="' . bp_get_members_directory_permalink() . '" class="cf"><i class="x-icon-male" data-x-icon="" aria-hidden="true"></i> <span>' . x_get_option( 'x_buddypress_members_title' ) . '</span></a></li>';
    
          if ( ! is_user_logged_in() ) {
            if ( bp_get_signup_allowed() ) {
              $submenu_items .= '<li class="menu-item menu-item-buddypress-navigation"><a href="' . bp_get_signup_page() . '" class="cf"><i class="x-icon-pencil" data-x-icon="" aria-hidden="true"></i> <span>' . x_get_option( 'x_buddypress_register_title' ) . '</span></a></li>';
              $submenu_items .= '<li class="menu-item menu-item-buddypress-navigation"><a href="' . bp_get_activation_page() . '" class="cf"><i class="x-icon-key" data-x-icon="" aria-hidden="true"></i> <span>' . x_get_option( 'x_buddypress_activate_title' ) . '</span></a></li>';
            }
            $submenu_items .= '<li class="menu-item menu-item-buddypress-navigation"><a href="' . wp_login_url() . '" class="cf"><i class="x-icon-sign-in" data-x-icon="" aria-hidden="true"></i> <span>' . __( 'Log in', '__x__' ) . '</span></a></li>';
          } else {
            $submenu_items .= '<li class="menu-item menu-item-buddypress-navigation"><a href="' . bp_loggedin_user_domain() . '" class="cf"><i class="x-icon-cog" data-x-icon="" aria-hidden="true"></i> <span>' . __( 'Profile', '__x__' ) . '</span></a></li>';
    
    		$submenu_items .= '<li class="menu-item menu-item-buddypress-navigation"><a href="' . wp_logout_url() . '" class="cf"><i class="x-icon-sign-out" data-x-icon=""></i> <span>' . __( 'Log Out', '__x__' ) . '</span></a></li>';
    
          }
    	
    
          if ( $args->theme_location == 'primary' ) {
            
            if (  is_user_logged_in() ) {
            $items .= '<li class="menu-item current-menu-parent menu-item-has-children x-menu-item x-menu-item-buddypress">'
                      . '<a href="' . $top_level_link . '" class="x-btn-navbar-buddypress">'
                        . '<span><i class="x-icon-user" data-x-icon="" aria-hidden="true"></i><span class="x-hidden-desktop"> ' . __( 'Social', '__x__' ) . '</span></span>'
                      . '</a>'
                      . '<ul class="sub-menu">'
                        . $submenu_items
                      . '</ul>'
                    . '</li>';
             } else {
    
             $items .= '<li class="menu-item current-menu-parent menu-item-has-children x-menu-item x-menu-item-buddypress">'
                      . '<a href="' . wp_login_url() . '" class="x-btn-navbar-buddypress">'
                        . '<span><i class="x-icon-user" data-x-icon="" aria-hidden="true"></i><span class="x-hidden-desktop"> ' . __( 'Log in', '__x__' ) . '</span></span>'
                      . '</a>'
                    . '</li>';
    
             }
    
          }
        }
    
        return $items;
    
      }
      add_filter( 'wp_nav_menu_items', 'x_buddypress_navbar_menu', 9997, 2 );

    Regarding the icon, the following part handles it:

             $items .= '<li class="menu-item current-menu-parent menu-item-has-children x-menu-item x-menu-item-buddypress">'
                      . '<a href="' . wp_login_url() . '" class="x-btn-navbar-buddypress">'
                        . '<span><i class="x-icon-user" data-x-icon="" aria-hidden="true"></i><span class="x-hidden-desktop"> ' . __( 'Log in', '__x__' ) . '</span></span>'
                      . '</a>'
                    . '</li>';

    From the code, it is the same user icon. Your site is not live yet so I can’t see this issue when logout.

    Hope this helps.

    #1211118

    leehart09
    Participant

    Thank you so much for your help. The X Support team is fantastic!

    When you are logged out, you can see a ‘login’ icon, and when you click on it, it brings you to the wordpress login screen. This may not be entirely clear to other people what the function of the ‘login’ icon is as they may not have seen it before (I myself wasn’t sure what the icon represented). Would it be possible to make the ‘Create an account’ and ‘Login’ sub-menus visible when people are logged out, so that when they hover over the icon they know what it represents?

    Thanks again!

    #1211409

    Lely
    Moderator

    Hi There,

    Please try updating the code to this:

    function x_buddypress_navbar_menu( $items, $args ) {
    
        if ( X_BUDDYPRESS_IS_ACTIVE && x_get_option( 'x_buddypress_header_menu_enable' ) == '1' ) {
    
          if ( bp_is_active( 'activity' ) ) {
            $logged_out_link = bp_get_activity_directory_permalink();
          } else if ( bp_is_active( 'groups' ) ) {
            $logged_out_link = bp_get_groups_directory_permalink();
          } else {
            $logged_out_link = bp_get_members_directory_permalink();
          }
    
          $top_level_link = ( is_user_logged_in() ) ? bp_loggedin_user_domain() : $logged_out_link;
          $submenu_items  = '';
    
          if ( bp_is_active( 'activity' ) ) {
            $submenu_items .= '<li class="menu-item menu-item-buddypress-navigation"><a href="' . bp_get_activity_directory_permalink() . '" class="cf"><i class="x-icon-thumbs-up" data-x-icon="" aria-hidden="true"></i> <span>' . x_get_option( 'x_buddypress_activity_title' ) . '</span></a></li>';
          }
    
          if ( bp_is_active( 'groups' ) ) {
            $submenu_items .= '<li class="menu-item menu-item-buddypress-navigation"><a href="' . bp_get_groups_directory_permalink() . '" class="cf"><i class="x-icon-sitemap" data-x-icon="" aria-hidden="true"></i> <span>' . x_get_option( 'x_buddypress_groups_title' ) . '</span></a></li>';
          }
    
          if ( is_multisite() && bp_is_active( 'blogs' ) ) {
            $submenu_items .= '<li class="menu-item menu-item-buddypress-navigation"><a href="' . bp_get_blogs_directory_permalink() . '" class="cf"><i class="x-icon-file" data-x-icon="" aria-hidden="true"></i> <span>' . x_get_option( 'x_buddypress_blogs_title' ) . '</span></a></li>';
          }
    
          $submenu_items .= '<li class="menu-item menu-item-buddypress-navigation"><a href="' . bp_get_members_directory_permalink() . '" class="cf"><i class="x-icon-male" data-x-icon="" aria-hidden="true"></i> <span>' . x_get_option( 'x_buddypress_members_title' ) . '</span></a></li>';
    
          if ( ! is_user_logged_in() ) {
            if ( bp_get_signup_allowed() ) {
              $submenu_items .= '<li class="menu-item menu-item-buddypress-navigation"><a href="' . bp_get_signup_page() . '" class="cf"><i class="x-icon-pencil" data-x-icon="" aria-hidden="true"></i> <span>' . x_get_option( 'x_buddypress_register_title' ) . '</span></a></li>';
              $submenu_items .= '<li class="menu-item menu-item-buddypress-navigation"><a href="' . bp_get_activation_page() . '" class="cf"><i class="x-icon-key" data-x-icon="" aria-hidden="true"></i> <span>' . x_get_option( 'x_buddypress_activate_title' ) . '</span></a></li>';
            }
            $submenu_items .= '<li class="menu-item menu-item-buddypress-navigation"><a href="' . wp_login_url() . '" class="cf"><i class="x-icon-sign-in" data-x-icon="" aria-hidden="true"></i> <span>' . __( 'Log in', '__x__' ) . '</span></a></li>';
          } else {
            $submenu_items .= '<li class="menu-item menu-item-buddypress-navigation"><a href="' . bp_loggedin_user_domain() . '" class="cf"><i class="x-icon-cog" data-x-icon="" aria-hidden="true"></i> <span>' . __( 'Profile', '__x__' ) . '</span></a></li>';
    
    		$submenu_items .= '<li class="menu-item menu-item-buddypress-navigation"><a href="' . wp_logout_url() . '" class="cf"><i class="x-icon-sign-out" data-x-icon=""></i> <span>' . __( 'Log Out', '__x__' ) . '</span></a></li>';
    
          }
    	
    
          if ( $args->theme_location == 'primary' ) {
            
            if (  is_user_logged_in() ) {
            $items .= '<li class="menu-item current-menu-parent menu-item-has-children x-menu-item x-menu-item-buddypress">'
                      . '<a href="' . $top_level_link . '" class="x-btn-navbar-buddypress">'
                        . '<span><i class="x-icon-user" data-x-icon="" aria-hidden="true"></i><span class="x-hidden-desktop"> ' . __( 'Social', '__x__' ) . '</span></span>'
                      . '</a>'
                      . '<ul class="sub-menu">'
                        . $submenu_items
                      . '</ul>'
                    . '</li>';
             } else {
    
             $items .= '<li class="menu-item current-menu-parent menu-item-has-children x-menu-item x-menu-item-buddypress">'
                      . '<a href="' . wp_login_url() . '" class="x-btn-navbar-buddypress">'
                        . '<span><i class="x-icon-user" data-x-icon="" aria-hidden="true"></i><span class="x-hidden-desktop"> ' . __( 'Log in', '__x__' ) . '</span></span>'
                      . '</a>'
                      . '<ul class="sub-menu">'
                        . $submenu_items
                      . '</ul>'
                    . '</li>';
    
             }
    
          }
        }
    
        return $items;
    
      }
      add_filter( 'wp_nav_menu_items', 'x_buddypress_navbar_menu', 9997, 2 );

    Hope this helps.

    #1211950

    leehart09
    Participant

    Hi Lely! Thank you for this. And I’m now able to see the ‘Log In’, and ‘Create an Account’ feature which I was hoping to see. However, it’s back to showing ‘Activity’, ‘Groups’, ‘Members’ and ‘Activate Your Account’ which I don’t want people who are logged out to have access to. Can these be hidden for logged out users?

    Broken down, this is what I would like to be shown:

    For logged out users:
    – Create an Account
    – Log In

    For logged in users:
    – Activity
    – Groups
    – Members
    – Profile
    – Logout

    It’s so close to being perfect! Thank you so much for your help.

    #1212454

    Lely
    Moderator

    Hi There,

    Thank you for the clarification. Please update to this:

    function x_buddypress_navbar_menu( $items, $args ) {
    
        if ( X_BUDDYPRESS_IS_ACTIVE && x_get_option( 'x_buddypress_header_menu_enable' ) == '1' ) {
    
          if ( bp_is_active( 'activity' ) ) {
            $logged_out_link = bp_get_activity_directory_permalink();
          } else if ( bp_is_active( 'groups' ) ) {
            $logged_out_link = bp_get_groups_directory_permalink();
          } else {
            $logged_out_link = bp_get_members_directory_permalink();
          }
    
          $top_level_link = ( is_user_logged_in() ) ? bp_loggedin_user_domain() : $logged_out_link;
          $submenu_items  = '';
    
          if ( bp_is_active( 'activity' ) ) {
    	  if (  is_user_logged_in() ) {
            $submenu_items .= '<li class="menu-item menu-item-buddypress-navigation"><a href="' . bp_get_activity_directory_permalink() . '" class="cf"><i class="x-icon-thumbs-up" data-x-icon="" aria-hidden="true"></i> <span>' . x_get_option( 'x_buddypress_activity_title' ) . '</span></a></li>';
          }
    	  }
    
          if ( bp_is_active( 'groups' ) ) {
    	  if (  is_user_logged_in() ) {
            $submenu_items .= '<li class="menu-item menu-item-buddypress-navigation"><a href="' . bp_get_groups_directory_permalink() . '" class="cf"><i class="x-icon-sitemap" data-x-icon="" aria-hidden="true"></i> <span>' . x_get_option( 'x_buddypress_groups_title' ) . '</span></a></li>';
          }
    	  }
    
          if ( is_multisite() && bp_is_active( 'blogs' ) ) {
            $submenu_items .= '<li class="menu-item menu-item-buddypress-navigation"><a href="' . bp_get_blogs_directory_permalink() . '" class="cf"><i class="x-icon-file" data-x-icon="" aria-hidden="true"></i> <span>' . x_get_option( 'x_buddypress_blogs_title' ) . '</span></a></li>';
          }
    
          if (  is_user_logged_in() ) {
          $submenu_items .= '<li class="menu-item menu-item-buddypress-navigation"><a href="' . bp_get_members_directory_permalink() . '" class="cf"><i class="x-icon-male" data-x-icon="" aria-hidden="true"></i> <span>' . x_get_option( 'x_buddypress_members_title' ) . '</span></a></li>';
          }
    	  
          if ( ! is_user_logged_in() ) {
            if ( bp_get_signup_allowed() ) {
              $submenu_items .= '<li class="menu-item menu-item-buddypress-navigation"><a href="' . bp_get_signup_page() . '" class="cf"><i class="x-icon-pencil" data-x-icon="" aria-hidden="true"></i> <span>' . x_get_option( 'x_buddypress_register_title' ) . '</span></a></li>';
              //$submenu_items .= '<li class="menu-item menu-item-buddypress-navigation"><a href="' . bp_get_activation_page() . '" class="cf"><i class="x-icon-key" data-x-icon="" aria-hidden="true"></i> <span>' . x_get_option( 'x_buddypress_activate_title' ) . '</span></a></li>';
            }
            $submenu_items .= '<li class="menu-item menu-item-buddypress-navigation"><a href="' . wp_login_url() . '" class="cf"><i class="x-icon-sign-in" data-x-icon="" aria-hidden="true"></i> <span>' . __( 'Log in', '__x__' ) . '</span></a></li>';
          } else {
            $submenu_items .= '<li class="menu-item menu-item-buddypress-navigation"><a href="' . bp_loggedin_user_domain() . '" class="cf"><i class="x-icon-cog" data-x-icon="" aria-hidden="true"></i> <span>' . __( 'Profile', '__x__' ) . '</span></a></li>';
    
    		$submenu_items .= '<li class="menu-item menu-item-buddypress-navigation"><a href="' . wp_logout_url() . '" class="cf"><i class="x-icon-sign-out" data-x-icon=""></i> <span>' . __( 'Log Out', '__x__' ) . '</span></a></li>';
    
          }
    	
    
          if ( $args->theme_location == 'primary' ) {
            
            if (  is_user_logged_in() ) {
            $items .= '<li class="menu-item current-menu-parent menu-item-has-children x-menu-item x-menu-item-buddypress">'
                      . '<a href="' . $top_level_link . '" class="x-btn-navbar-buddypress">'
                        . '<span><i class="x-icon-user" data-x-icon="" aria-hidden="true"></i><span class="x-hidden-desktop"> ' . __( 'Social', '__x__' ) . '</span></span>'
                      . '</a>'
                      . '<ul class="sub-menu">'
                        . $submenu_items
                      . '</ul>'
                    . '</li>';
             } else {
    
             $items .= '<li class="menu-item current-menu-parent menu-item-has-children x-menu-item x-menu-item-buddypress">'
                      . '<a href="' . wp_login_url() . '" class="x-btn-navbar-buddypress">'
                        . '<span><i class="x-icon-user" data-x-icon="" aria-hidden="true"></i><span class="x-hidden-desktop"> ' . __( 'Log in', '__x__' ) . '</span></span>'
                      . '</a>'
                      . '<ul class="sub-menu">'
                        . $submenu_items
                      . '</ul>'
                    . '</li>';
    
             }
    
          }
        }
    
        return $items;
    
      }
      add_filter( 'wp_nav_menu_items', 'x_buddypress_navbar_menu', 9997, 2 );

    Hope this helps.

    #1218308

    leehart09
    Participant

    This worked perfect – exactly how I want it to appear! Thank you so much! 🙂