Showing Member Type on BuddyPress Profile

Want to show Member Type on BuddyPress profile in between user-nickname (@farmand) and activity (active 2 minutes ago) See https://www.socialfaucet.net/members/farmand/. I have tried the following code but not able to achieve expected result.

// Member type showing in profile

function using_mt_member_header_display() {
$member_type = bp_get_member_type( bp_displayed_user_id() );

if ( empty( $member_type ) ) {
return;
}

$member_type_object = bp_get_member_type_object( $member_type );
?>
<p class="member_type"><?php echo esc_html( $member_type_object->labels['singular_name'] ); ?></p>

<?php
}
add_action( 'bp_before_member_header_meta', 'using_mt_member_header_display' );
?>

  • Predrag Dubajic

    Hi Mikkel,

    Hope you're doing well today :slight_smile:

    I did some tests on my end with the above code and it display Member Type on my installation without any issues so it seems it's something specific to your installation that's causing the issue.

    I see that you use custom theme and have over 70 plugins installed there so it's possible that one of those is preventing the above code from working properly.

    Can you try disabling your other plugins and switching to default theme to see if the code will work after that?

    Best regards,
    Predrag

    • Mikkel

      Hi Predrag,

      Yeah, this also work on my install, but what i want help for, was to move where the member type was showing.
      Instead of showing in top of the profile page, i want to show it in the green area where it show username, picture and such instead, if that is possible?
      I asked support if there was a way to change above code, so the member type would show up there instead of top of the page.

      Sorry for misunderstanding

      Best regards,

  • Predrag Dubajic

    Hi Mikkel,

    I think that the issue here is your theme because I see there are some differences in HTML structure of your and mine profile pages.

    For example, I have item-header-content holder wrapping my account info, and that's where the Member Type gets added for me as well, but there's no such holder in your theme so it doesn't add it there and instead uses different location.

    So first thing I would suggest is to check your theme and see if you can get it back to use default BuddyPress structure and the code should work better after that.

    Or what we could do is to use a bit of jQuery and move the element in correct place on page load, but for this I would need to see the field on your site first so I can check what code we can use.

    Best regards,
    Predrag

  • Predrag Dubajic

    Hi Mikkel,

    Here's a screenshot of my installation where you can see that member_type is inside item-header-content:

    Now, I was actually able to find the same holder on your site but the structure is still different as it doesn't hold the same data as on default WP theme, this is HTML structure from your site:

    I haven't changed the theme, only there is added that child theme, and then Simple CSS plugin to add some css code..

    This due to theme HTML structure, not CSS I'm afraid and we need to move the HTML holder of member_type into different holder altogether.

    Note that this is from your live site, I tried adding hosts file to go to your test file as you told Nithin in chat, but I didn't see member type in there as well.

    Best regards,
    Predrag

    • Mikkel

      Hi Predrag,

      Ok i see.
      I tried to install a brand new wp install and then put in same plugins and themes as from live site..
      Can you try check the test site now? The one with same domain name just on the other IP..

      After i made the new install on test site my customizer is working again, but i still have problem with showing up the theme footer in frontend..It shows up in customizer, but not in frontend, maybe these problems can be related?

  • Predrag Dubajic

    Hi Mikkel,

    Ok, I can see the test site now, and I was able to replicate the issue by using the same thing that you're using.
    Now the issue is still within the theme itself and how it handles BuddyPress HTML and I would suggest getting in touch with the theme developers about this, especially since the theme doesn't follow basic WP development rules which can be seen by the way that CSS is included inside main style.css file.

    What you can do is add a small script to move member typer in another place and this should do the trick:

    function move_member_type() { ?>
    <script type="text/javascript">
    	jQuery( document ).ready(function() {
    	    jQuery('.member_type').appendTo('#item-header-meta');
    	});
    </script>
    <?php }
    add_action( 'wp_footer', 'move_member_type' );

    You can add that to functions.php or as a mu-plugin.

    As for the footer issue, I saw same issue on my end when I installed the theme but once I edited footer content from Appearance > Customizer it did show it properly on both front and backend after saving my changes.

    Best regards,
    Predrag

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.