I have added this code but not worked for me
/**
* Inject classes to body based on displayed user’s member types.
*
* @param array $classes array of css classes.
*
* @return array
*/
function buddydev_add_membertype_to_body_class( $classes = array() ) {if ( ! bp_is_user() ) {
return $classes;
}$member_types = bp_get_member_type( bp_displayed_user_id(), false );
if ( ! $member_types ) {
return $classes;
}foreach ( $member_types as $member_type ) {
$classes[] = ‘member-type-‘ . $member_type; // member-type-student etc.
}return $classes;
}add_filter( ‘bp_get_the_body_class’, ‘buddydev_add_membertype_to_body_class’ );
I am using
wordpress 5.6.2
buddypress 7.2.0Hi,
That code is for displayed user’s member type.you may use the following instead
/** * Inject classes to body based on logged user's member types. * * @param array $classes array of css classes. * * @return array */ function buddydev_add_membertype_to_body_class( $classes = array() ) { if ( ! is_user_logged_in() ) { return $classes; } $member_types = bp_get_member_type( get_current_user_id(), false ); if ( ! $member_types ) { return $classes; } foreach ( $member_types as $member_type ) { $classes[] = 'logged-member-type-' . $member_type; // member-type-student etc. } return $classes; } add_filter( 'bp_get_the_body_class', 'buddydev_add_membertype_to_body_class' );
This adds logged user’s member types.
Regards
BrajeshHi Waseem,
Thank you for confirming. I am glad it worked.Regards
Brajesh
The topic ‘ [Resolved] buddypress member type as a body class name when user is logged in’ is closed to new replies.