This topic has 14 replies, 5 voices, and was last updated 9 years by 5high-photohub.

  • Author
  • #49609
     stevejenkins
    Participant

    I’m trying to use the Display Name instead of the @username in my Profile Header.

    Any straightforward way to do this in functions.php? I’d rather not tinker with core files so that upgrades don’t overwrite.

    Thanks! πŸ™‚

    Steve

    #49685
     stevejenkins
    Participant

    Got it figured out — put a copy of member-header.php in my child theme folder and went to town! πŸ™‚

    #49714
     Laura
    Moderator

    Hello, i’m glad you could resolve it! Please share your change so others may find it helpfull

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution

    Laura Solanes - Graphic Designer and Web Designer

    Please be patient as I try to answer each topic as fast as i can.

    If you like the theme or the support you've received please consider leaving us a review on Themeforest!

    Always happyΒ to help you πŸ™‚

    #50060
     arqabs
    Participant

    @stevejenkins could you please post your solution?

    best regards!

    #50074
     sharmstr
    Moderator

    He copied member-header.php to his child theme (its located in /kleo/buddypress/members/single). If you look at that file, the @ is on line 26. Delete it. Then change bp_displayed_user_mentionname to echo bp_core_get_user_displayname( bp_displayed_user_id() ).

    So the entire line should be

    COPY CODE
    
    <h4 class="user-nicename"><?php echo bp_core_get_user_displayname( bp_displayed_user_id() ); ?></h4>
    

    (sorry, hit submit before pasting all of the solution)

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution

    This support site is not about custom work. If you need custom development please contact cornel@seventhqueen.com

    #50080
     stevejenkins
    Participant

    It was SLIGHTLY more complex than that, Sharmstr. πŸ™‚

    First, keep in mind that my site is subscription only and for a private non-profit association with a couple thousand members, so we don’t have problems exposing personal info to each other. Your standard user isn’t going to want their email address exposed to the world.

    First, I’ve added these functions to my functions.php:

    COPY CODE
    // Put Profile User's Email Address in Profile Header
    function DisplayedUserEmail() {
    global $bp;
    echo '<br /><div class="bp_header_email"><a href="mailto:'. $bp->displayed_user->userdata->user_email .'" target="_blank">'. $bp->displayed_user->userdata->user_email .'</a></div>';
    }
    
    //add_action( 'bp_before_member_header_meta', 'DisplayedUserEmail' );
    
    // Put Profile User's Display Name at top of profile
    function DisplayedUserFullName() {
    global $bp;
    
    echo '<h2 class="user-nicenmame bp_header_displayname">'. $bp->displayed_user->fullname. '</h2>';
    }
    add_action( 'bp_before_member_header', 'DisplayedUserFullName' );
    

    Then you can apply your own custom CSS to the bp_header_email and bp_header_displayname classes.

    Next, copy

    /wp-content/themes/kleo/buddypress/members/single/member-header.php

    to

    /wp-content/themes/kleo-child/buddypress/members/single/member-header.php

    This will allow the child theme version of the file to override.

    Then edit the member-header.php file so it contains what you want. For those who like diff, here are the differences between the original and my edits:

    COPY CODE
    # diff /www/vhosts/example.com/htdocs/wp-content/themes/kleo-child/buddypress/members/single/member-header.php /www/vhosts/example.com/htdocs/wp-content/themes/kleo/buddypress/members/single/member-header.php
    24,25d23
    < <div>
    < <h4 class="user-nicename"><?php echo xprofile_get_field_data('31'); ?><br>
    27,36c25,29
    < <?php
    < global $bp;
    < echo '<a href="mailto:'. $bp->displayed_user->userdata->user_email .'" target="_blank">'.$bp->displayed_user->userdata->user_email .'</a>'; ?>
    < </h4>
    < </div>
    <
    < <span class="activity">
    < <?php if ( bp_is_active( 'activity' ) && bp_activity_do_mentions() ) : ?>
    <       @<?php bp_displayed_user_mentionname(); ?>: <?php bp_last_activity( bp_displayed_user_id() ); ?></span>
    < <?php endif; ?>
    ---
    >       <?php if ( bp_is_active( 'activity' ) && bp_activity_do_mentions() ) : ?>
    >               <h4 class="user-nicename">@<?php bp_displayed_user_mentionname(); ?></h4>
    >       <?php endif; ?>
    >
    >       <span class="activity"><?php bp_last_activity( bp_displayed_user_id() ); ?></span>
    

    My entire member-header.php (in its edited state) looks like this:

    COPY CODE
    <?php
    
    /**
     * BuddyPress - Users Header
     *
     * @package BuddyPress
     * @subpackage bp-legacy
     */
    
    ?>
    
    <?php do_action( 'bp_before_member_header' ); ?>
    
    <div id="item-header-avatar" class="rounded">
            <a href="<?php bp_displayed_user_link(); ?>">
    
                    <?php bp_displayed_user_avatar( 'type=full' ); ?>
    
            </a>
      <?php do_action('bp_member_online_status', bp_displayed_user_id()); ?>
    </div><!-- #item-header-avatar -->
    
    <div id="item-header-content" <?php if (isset($_COOKIE['bp-profile-header']) && $_COOKIE['bp-profile-header'] == 'small') {echo 'style="display:none;"';} ?>>
    <div>
    <h4 class="user-nicename"><?php echo xprofile_get_field_data('31'); ?><br>
    
    <?php
    global $bp;
    echo '<a href="mailto:'. $bp->displayed_user->userdata->user_email .'" target="_blank">'.$bp->displayed_user->userdata->user_email .'</a>'; ?>
    </h4>
    </div>
    
    <span class="activity">
    <?php if ( bp_is_active( 'activity' ) && bp_activity_do_mentions() ) : ?>
            @<?php bp_displayed_user_mentionname(); ?>: <?php bp_last_activity( bp_displayed_user_id() ); ?></span>
    <?php endif; ?>
    
            <?php do_action( 'bp_before_member_header_meta' ); ?>
    
            <div id="item-meta">
    
                    <?php if ( bp_is_active( 'activity' ) ) : ?>
    
                            <div id="latest-update">
    
                                    <?php bp_activity_latest_update( bp_displayed_user_id() ); ?>
    
                            </div>
    
                    <?php endif; ?>
    
                    <div id="item-buttons">
    
                            <?php do_action( 'bp_member_header_actions' ); ?>
    
                    </div><!-- #item-buttons -->
    
                    <?php
                    /***
                     * If you'd like to show specific profile fields here use:
                     * bp_member_profile_data( 'field=About Me' ); -- Pass the name of the field
                     */
                     do_action( 'bp_profile_header_meta' );
    
                     ?>
    
            </div><!-- #item-meta -->
    
    </div><!-- #item-header-content -->
    
    <?php do_action( 'bp_after_member_header' ); ?>
    
    <?php do_action( 'template_notices' ); ?>
    #50081
     stevejenkins
    Participant

    Can’t figure out how to modify my post, but if it wasn’t clear, you should only modify the child theme version of the member-header.php file.

    #50084
     sharmstr
    Moderator

    πŸ™‚ You didnt say that in your first post. All you said was “Display Name instead of the @username ” which is that simple πŸ™‚

    Oops. Forgot to add. Thanks for sharing.

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution

    This support site is not about custom work. If you need custom development please contact cornel@seventhqueen.com

    #50119
     stevejenkins
    Participant

    πŸ™‚

    #50410
     5high-photohub
    Participant

    hey Sharmstr, you said ‘(sorry, hit submit before pasting all of the solution)’ – can you post the full solution? as this is just what I’m after!
    cheers.

    #50450
     sharmstr
    Moderator

    That is the full solution. I wrote that after I hit submit (I have edit capabilities)

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution

    This support site is not about custom work. If you need custom development please contact cornel@seventhqueen.com

    #50670
     5high-photohub
    Participant

    Great! Will give it a go – can I just add in the member-header.php directly into my child theme folder (ie: /kleo-child/member-header.php), or do i have to add in the full folder structure like Steve mentioned above (ie: /kleo-child/buddypress/members/single/member-header.php)?
    Thanks again, J

    #50672
     5high-photohub
    Participant

    OK, I’ve just tried it without the full folder structure and it didn’t work. But maybe it was my code? – as what I was actually trying to do was to have the user’s display name sitting above their @name + activity.

    So it would look like this:
    Avatar
    Display name
    @name + activity

    And this is the code i used, at line 25:

    COPY CODE
    <?php if ( bp_is_active( 'activity' ) && bp_activity_do_mentions() ) : ?>
    		/***
    		 * added in a users display name under avatar and above the @name in profile.
    		 */
    	        <h4 class="user-nicename"><?php echo bp_core_get_user_displayname( bp_displayed_user_id() ); ?></h4>
    		<h4 class="user-nicename">@<?php bp_displayed_user_mentionname(); ?></h4>
    	<?php endif; ?>

    Should that work?
    many thanks,
    Jenny

    #50679
     sharmstr
    Moderator

    You need to keep the directory structure. http://codex.wordpress.org/Child_Themes

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution

    This support site is not about custom work. If you need custom development please contact cornel@seventhqueen.com

    #50680
     5high-photohub
    Participant

    Thanks for that – all works now. I’ve read around a bit about adding in line breaks in .php files and it seems Ok to use htm tags – like below:

    COPY CODE
    	<?php if ( bp_is_active( 'activity' ) && bp_activity_do_mentions() ) : ?>
    	        <br><h4 class="user-nicename"><?php echo bp_core_get_user_displayname( bp_displayed_user_id() ); ?></h4></br>
    		<h4 class="user-nicename">@<?php bp_displayed_user_mentionname(); ?></h4>
    	<?php endif; ?>

    is that right? it works, though does seem to be rather a large gap between lines.
    cheers.

Viewing 15 posts - 1 through 15 (of 15 total)

The forum ‘Plugins questions’ is closed to new topics and replies.

Log in with your credentials

Forgot your details?