Skip to:
Content
Pages
Categories
Search
Top
Bottom

Putting the @username below name


  • Tanya
    Participant

    @pjtna

    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

    @sambora5150

    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

    @mitesh-patel

    @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);`


    Tanya
    Participant

    @pjtna

    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

    @sambora5150

    Thanks !!! it worked for me too!!

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

     


    redknite
    Participant

    @redknite

    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

    @redknite

    can someone please help?


    redknite
    Participant

    @redknite

    @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

    @tecca

    @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

    @palmdoc

    @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

    @palmdoc

    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

    @teppom

    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

    @palmdoc

    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

    @robin-w

    @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

    @palmdoc

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


    Robin W
    Moderator

    @robin-w

    great – glad you’re fixed !


    david_ma
    Participant

    @david_ma

    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

    @robin-w

    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 ) ); ?>
    

    For Games
    Participant

    @sockscap64

    @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