Skip to:
Content
Pages
Categories
Search
Top
Bottom

Putting the @username below name

  • @pjtna

    Participant

    I am trying to add the username underneath a person’s avatar, like in these forums (circled in the pic above). I know where to add the code in loop-single-reply.php and I have tried looking in the beta release of bbPress 2.3 in case it was included there, but I am not having any luck.

    Would anyone know what code I would need to insert to bring up the username?

Viewing 18 replies - 1 through 18 (of 18 total)
  • @sambora5150

    Participant

    Hi, i think this is the code  i have it from this other topic:

    How to display @username in bbPress?

     

    i don´t know where tu place it… can anyone help me?

    user = get_userdata( $user_id );
    if ( !empty( $user->user_nicename ) ) {
        $user_nicename = $user->user_nicename;
    }

    @mitesh-patel

    Participant

    @pjtna and @sambora5150 : Lucky, you guys found me, (or viceversa :))

    I was looking to do exactly that. So here it is.

    The code should go in bbpress template file loop-single-reply.php, below the PHP code line that contains. The file is located in plugins > bbpress > templates > default > bbpress folder.

    `do_action( ‘bbp_theme_before_reply_author_admin_details’ )`
    Th actual code should be,
    `
    $user = get_userdata( bbp_get_reply_author_id() );
    if ( !empty( $user->user_nicename ) ) {
    $user_nicename = $user->user_nicename;
    echo “@”.$user_nicename;
    }
    `

    But you should never edit that file, as the changes will be lost when you upgrade bbpress plugin.

    So, copy the file and put it in your theme within a folder ‘bbpress’ (you will have to create that folder).

    You will also need to add the following line to your theme’s function.php

    add_theme_support(‘bbpress’);

    OR untested but simple method, add all of the following to the function.php of your theme.

    `function append_mention(){
    $user = get_userdata( bbp_get_reply_author_id() );
    if ( !empty( $user->user_nicename ) ) {
    $user_nicename = $user->user_nicename;
    echo “@”.$user_nicename;
    }
    }

    add_action(bbp_theme_before_reply_author_admin_details, append_mention);`

    @pjtna

    Participant

    Thanks @mitesh-patel, that worked perfectly!

    I was hoping if you could help me out with putting the username on the list of topics page (such as on bbpress.org/support) in the freshness column? Currently, there is just the person’s name.

    @sambora5150

    Participant

    Thanks !!! it worked for me too!!

      @mitesh-patel i´m very pleased!!! thanks

     

    @redknite

    Participant

    i can’t seem to get this to work… so it’s supposed to look like this?:

    <?php do_action( 'bbp_theme_before_reply_author_details' ); ?>
    $user = get_userdata( bbp_get_reply_author_id() );
    if ( !empty( $user->user_nicename ) ) {
    $user_nicename = $user->user_nicename;
    echo “@”.$user_nicename;
    }
    <?php bbp_reply_author_link( array( 'sep' => '<br />', 'show_role' => true ) ); ?>

    I get a parse error when i do this. What am i doing wrong?

    @redknite

    Participant

    can someone please help?

    @redknite

    Participant

    @pjtna or @sambora5150 can you tell me how you got this to work? Where did you put the code? and was it exactly like above or did you have to add additional code?

    @tecca

    Participant

    @redknite, put this in your loop-single-reply.php file:

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

    @palmdoc

    Participant

    @Tecca – I tried but it doesn’t display the @username. Where exactly in the loop-single-reply.php does one put it? Sorry noob here.

    @palmdoc

    Participant

    OK there was a similar question in the Buddyboss forums and if you are using the Buddyboss theme, it should be put in the bbpress subfolder (copy to child theme if not there) in the oop-single-reply.php file after the
    <?php do_action( 'bbp_theme_after_reply_author_details' ); ?>

    Now a further question – if I want to replace the Real Name displayed with only the @username, what should I do?
    Thanks!

    @teppom

    Participant

    Thanks for the thread. Based on this I managed to develop a solution that does not require hassling with the template files. Just add this to function.php in your theme:

    /**
    * 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;
    }
    }
    

    @palmdoc

    Participant

    Hi @teppom
    I tried it with my childtheme (Buddyboss) and I am getting blank page on my forum.
    Not sure what the problem is.

    @robin-w

    Moderator

    @palmdoc – can’t see anything wrong with teppom’s code and just double checked by loading it.

    Check that you have added it correctly to your functions file.

    @palmdoc

    Participant

    @teppom @robin-w
    It works. Many thanks!

    @robin-w

    Moderator

    great – glad you’re fixed !

    @david_ma

    Participant

    How about remove the authors real name and email linked avatar? My users want to use their username only, and a custom avatar.

    This worked well for adding the username, so if i can just remove the full name/image, that out to do it.

    /**
    * 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;
    }
    }

    @robin-w

    Moderator

    This worked well for adding the username, so if i can just remove the full name/image, that out to do it.

    If you mean the two bits above what you have just added , then the simplest would be

    create a directory on your theme called ‘bbpress’
    ie wp-content/%your-theme-name%/bbpress
    find
    wp-content/plugins/bbpress/templates/default/bbpress/loop-single-reply.php
    Make a copy of this file, and put in in the directory called bbpress that you created above, so you end up with
    wp-content/%your-theme-name%/bbpress/loop-single-reply.php
    bbPress will now use this template instead of the original

    Then simply delete line 45

    <?php bbp_reply_author_link( array( 'sep' => '<br />', 'show_role' => true ) ); ?>
    

    @sockscap64

    Participant

    @sockscap64
    is that working?

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