Skip to:
Content
Pages
Categories
Search
Top
Bottom

Display first name instead of username on single reply


  • aaronbennett2097
    Participant

    @aaronbennett2097

    Hi everyone.

    I’m trying to change the loop-single-reply template to display the users first name instead of username, I’ve created a child theme and have the necessary templates in the bbpress folder, I think it’s the following line I need to replace…

    <?php bbp_reply_author_link( array( ‘sep’ => ‘<br />’, ‘show_role’ => false ) ); ?>

    From what I can tell, this displays the avatar and username, whereas I want it to show the avatar then firstname, but not found any way to do this.

    Does anyone have any ideas?

    Thanks

Viewing 1 replies (of 1 total)

  • Robin W
    Moderator

    @robin-w

    not tested but try adding this to your functions file

    add_filter( 'bbp_get_reply_author_display_name', 'rew_display_first_name' 10, 2);
    
    function rew_display_first_name ($author_name, $reply_id ) {
    	$reply_id = bbp_get_reply_id( $reply_id );
    
    		// User is not a guest
    		if ( !bbp_is_reply_anonymous( $reply_id ) ) {
    
    			// Get the author ID
    			$author_id = bbp_get_reply_author_id( $reply_id );
    
    			// Try to get a display name
    			$author_name = get_the_author_meta( 'first_name', $author_id );
    
    			// Fall back to user login
    			if ( empty( $author_name ) ) {
    				$author_name = get_the_author_meta( 'user_login', $author_id );
    			}
    
    		// User does not have an account
    		} else {
    			$author_name = get_post_meta( $reply_id, '_bbp_anonymous_name', true );
    		}
    
    		// If nothing could be found anywhere, use Anonymous
    		if ( empty( $author_name ) )
    			$author_name = __( 'Anonymous', 'bbpress' );
    
    		// Encode possible UTF8 display names
    		if ( seems_utf8( $author_name ) === false )
    			$author_name = utf8_encode( $author_name );
    
    return apply_filters( 'rew_display_first_name', $author_name, $reply_id );
    }
Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.
Skip to toolbar