Navigation
This is archived content. Visit our new forum.

Tagged: 

  • Author
    Posts
  • #1057021
    yahya92
    Participant

    Hello there,
    so I saw some of the questions here about how to put login/ register links in top bar but unfortunately the provided solutions are weak.
    you see in any site we see Login and Register link and when we login we see logout link with access to user profile
    how to achieve that?

    #1057503
    Rue Nel
    Moderator

    Hi There,

    Thanks for writing in!

    To have a Register and Login link in your topbar, we must first create a shortcode that will easily handle this function. If you already have your child theme active and ready, please insert this following code in your child theme’s functions.php file.

    // Custom login/logout/register shortcode
    // =============================================================================
    function custom_loginlogout($atts){
      extract( shortcode_atts( array(
        'separator'          => ''
      ), $atts, 'loginlogout' ) );
    
      $content = wp_loginout(null, false) . ' <span class="sep">' . $separator . '</span> ';
    
      if ( is_user_logged_in() ) {
        $content .= wp_register('', '', false);
      } else{
        $content .= wp_register('', '', false);
      }
    
      return $content;
    }
    add_shortcode('loginlogout', 'custom_loginlogout' );
    // =============================================================================

    After adding the code above, you need to edit your topbar content, Appearance > Customize > Header > Miscellaneous > Topbar Content and insert our new shortcode:

    
    [loginlogout separator="|"]

    And by default, the topbar content doesn’t display any shortcode. You also need to add this code in your child theme’s functions.php file so that our shortcode will be displayed.

    // Allow shortcodes in the topbar content
    // =============================================================================
    function allow_custom_shortcodes($contents) {
      $contents = do_shortcode($contents);
      return $contents;
    }
    add_filter('x_option_x_topbar_content', 'allow_custom_shortcodes');
    // =============================================================================

    Please note that the register link will only appear if you allow registrations in Settings > General.

    We would loved to know if this has work for you. Thank you.

    #1061143
    yahya92
    Participant

    thanks,it works (y)

    #1061153
    Rue Nel
    Moderator

    You’re welcome! We’re happy to help you out.
    If you need anything else we can help you with, don’t hesitate to open another thread.

    #1063993
    yahya92
    Participant

    there is an issue, when the user is logged in the log in link become “manage site”, while I need it to be a link to user buddypress profile

    #1064393
    Paul R
    Moderator

    Hi,

    Would you mind providing us with login credentials so we can take a closer look? To do this, you can make a post with the following info:

    – Link to your site
    – WordPress Admin username / password
    – FTP credentials

    Don’t forget to select Set as private reply. This ensures your information is only visible to our staff.

    #1064549
    yahya92
    Participant
    This reply has been marked as private.
    #1064704
    Paul R
    Moderator

    Hi

    Please change the code that pertains to Custom login/logout/register shortcode with this.

    
    // Custom login/logout/register shortcode
    // =============================================================================
    function custom_loginlogout($atts){
      extract( shortcode_atts( array(
        'separator'          => ''
      ), $atts, 'loginlogout' ) );
    
      $content = wp_loginout(null, false) . ' <span class="sep">' . $separator . '</span> ';
    
      if ( is_user_logged_in() ) {
            if ( function_exists( 'bp_loggedin_user_domain' ) ) :
                global $current_user;
                $content .= '<a href="'.home_url() . '/الأعضاء/' . $current_user->user_login . '/profile/">My Profile</a>';
            else:
               $content .= wp_register('', '', false);
            endif;
      } else{                          
        $content .= wp_register('', '', false);
      }
    
      return $content;
    }
    add_shortcode('loginlogout', 'custom_loginlogout' );
    // =============================================================================
    

    Hope that helps.

    #1066762
    yahya92
    Participant

    although the when I click on My Profile the link is 100% true I get 404 page!

    #1067454
    Rad
    Moderator

    Hi there,

    Please replace this line of code,

    $content .= '<a href="'.home_url() . '/الأعضاء/' . $current_user->user_login . '/profile/">My Profile</a>';

    with this one,

    $content .= '<a href="'.bp_loggedin_user_domain().'">My Profile</a>';

    Hope this helps.

    #1067922
    yahya92
    Participant

    thumbs up
    thank you

    #1067999
    Rue Nel
    Moderator

    You’re welcome!
    We’re glad we were able to help you out.

  • <script> jQuery(function($){ $("#no-reply-1057021 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>