Skip to:
Content
Pages
Categories
Search
Top
Bottom

How to add a @username

Viewing 11 replies - 1 through 11 (of 11 total)

  • Robkk
    Moderator

    @robkk

    How to add a @username like BBPress forum

    <?php $user = get_userdata( bbp_get_reply_author_id() );
    if ( !empty( $user->user_nicename ) ) {
    $user_nicename = $user->user_nicename;
    echo "@".$user_nicename;
    } ?>

    you add this to your loop-single-reply.php template


    Robin W
    Moderator

    @robin-w

    or put

    /**
    * Add @mentionname after bbpress forum author details
    */
    
    add_action( 'bbp_theme_after_reply_author_details', 'mentionname_to_bbpress' );
    function mentionname_to_bbpress () {
    $user = get_userdata( bbp_get_reply_author_id() );
    if ( !empty( $user->user_nicename ) ) {
    $user_nicename = $user->user_nicename;
    echo "@".$user_nicename;
    }
    }
    

    in your functions file.

    Functions files and child themes – explained !

    both methods are valid, if you use @robkk’s method, remember to create this as a separate file within your theme
    https://codex.bbpress.org/step-by-step-guide-to-setting-up-a-bbpress-forum-part-3/ section 3


    Robin W
    Moderator

    @robin-w

    to do the second you need to put the following in your functions file:

    //take away the role display
    function hide_role ($args) {
    $args['show_role'] = false ;
    Return $args ;
    }
    add_filter ('bbp_before_get_reply_author_link_parse_args', 'hide_role') ;

    this removes the existing text,

    then you’d need to add some image depending on role, so something like

    add_action( 'bbp_theme_after_reply_author_details', 'add_image' );
    function add_image () {
    $role = bbp_get_user_display_role( bbp_get_reply_author_id( $reply_id ) );
    if ($role == 'keymaster') {
    echo "<img src='/snippet_theme/img/error.gif' title='Error' alt='Error' />"; 
    }
    if ($role == 'participant') {
    etc.
    }
    
    

    This is not tested – sorry but limited time !!


    Leonyipa
    Participant

    @leonyipa

    Thanks for super fast help! 🙂
    I will try it right now!


    Leonyipa
    Participant

    @leonyipa

    It works! And it looks really pretty now!! Thanks 🙂

    how do I change the font colour of @username? (e.g. grey like BBPress forum)


    Robkk
    Moderator

    @robkk

    how do I change the font colour of @username?

    im going to use my version though , cause i dont know how with the add action version

    <p class=bbp-user-nicename><?php $user = get_userdata( bbp_get_reply_author_id() );
    if ( !empty( $user->user_nicename ) ) {
    $user_nicename = $user->user_nicename;
    echo "@".$user_nicename;
    } ?></p>

    throw this into custom css

    #bbpress-forums p.bbp-user-nicename {
    font-weight: bold;
    color: #888;
    display: inline-block;
    margin: 0;
    }

    Robin W
    Moderator

    @robin-w

    basically you’d use the same css as @robkk into your stylsheet, and then the code would be

    
    /**
    * Add @mentionname after bbpress forum author details
    */
    
    add_action( 'bbp_theme_after_reply_author_details', 'mentionname_to_bbpress' );
    function mentionname_to_bbpress () {
    $user = get_userdata( bbp_get_reply_author_id() );
    if ( !empty( $user->user_nicename ) ) {
    $user_nicename = $user->user_nicename;
    echo '<p class=bbp-user-nicename>' ;
    echo "@".$user_nicename.'</p>' ;
    }
    }
    

    Leonyipa
    Participant

    @leonyipa

    Thanks, where can I find custom css?

    also, can I use;

    add_action( ‘bbp_theme_after_reply_author_details’, ‘mentionname_to_bbpress’ );
    function mentionname_to_bbpress () {
    $user = get_userdata( bbp_get_reply_author_id() );
    if ( !empty( $user->user_nicename ) ) {
    $user_nicename = $user->user_nicename;
    echo ‘<font class=bbp-user-nicename>’ ;
    echo “@”.$user_nicename.'</font>’ ;
    }
    }

    use font instead of <p> ? because p will skip a line which makes the name and user role very far away


    Robin W
    Moderator

    @robin-w

    ok, put the css in your style.css.

    then maybe try this code in your functions.php file

    add_action( ‘bbp_theme_after_reply_author_details’, ‘mentionname_to_bbpress’ );
    function mentionname_to_bbpress () {
     $user = get_userdata( bbp_get_reply_author_id() );
     if ( !empty( $user->user_nicename ) ) {
     $user_nicename = $user->user_nicename;
    echo '<ul><li><font class=bbp-user-nicename>' ; 
    echo “@”.$user_nicename.’</font></li></ul>’ ;
     }
     }

    Leonyipa
    Participant

    @leonyipa

    Thanks very much!! 🙂
    It looks very pretty now 😛


    Robin W
    Moderator

    @robin-w

    great – glad you’re fixed !

Viewing 11 replies - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.
Skip to toolbar