This topic has 14 replies, 5 voices, and was last updated 9 years by 5high-photohub.
-
Author
-
March 11, 2015 at 02:10 #49609stevejenkinsParticipant
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
March 11, 2015 at 16:08 #49685stevejenkinsParticipantGot it figured out — put a copy of member-header.php in my child theme folder and went to town! π
March 11, 2015 at 17:40 #49714LauraModeratorHello, 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 solutionLaura 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 π
March 13, 2015 at 20:47 #50060arqabsParticipant@stevejenkins could you please post your solution?
best regards!
March 13, 2015 at 23:07 #50074sharmstrModeratorHe 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 solutionThis support site is not about custom work. If you need custom development please contact cornel@seventhqueen.com
March 14, 2015 at 00:06 #50080stevejenkinsParticipantIt 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' ); ?>
March 14, 2015 at 00:08 #50081stevejenkinsParticipantCan’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.
March 14, 2015 at 00:31 #50084sharmstrModeratorπ 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 solutionThis support site is not about custom work. If you need custom development please contact cornel@seventhqueen.com
March 17, 2015 at 09:28 #504105high-photohubParticipanthey 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.March 17, 2015 at 16:16 #50450sharmstrModeratorThat 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 solutionThis support site is not about custom work. If you need custom development please contact cornel@seventhqueen.com
March 18, 2015 at 04:18 #506705high-photohubParticipantGreat! 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, JMarch 18, 2015 at 04:44 #506725high-photohubParticipantOK, 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 + activityAnd 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,
JennyMarch 18, 2015 at 05:16 #50679sharmstrModeratorYou 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 solutionThis support site is not about custom work. If you need custom development please contact cornel@seventhqueen.com
March 18, 2015 at 05:44 #506805high-photohubParticipantThanks 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. -
AuthorPosts
The forum ‘Plugins questions’ is closed to new topics and replies.