bp_get_the_body_class( array $wp_classes = array(), array|bool $custom_classes = false )

Customize the body class, according to the currently displayed BP content.

Description

Uses the above is_() functions to output a body class for each scenario.

Parameters

$wp_classes

(array) (Optional) The body classes coming from WP.

Default value: array()

$custom_classes

(array|bool) (Optional) Classes that were passed to get_body_class().

Default value: false

Return

(array) $classes The BP-adjusted body classes.

Source

File: bp-core/bp-core-template.php

	function bp_get_the_body_class( $wp_classes = array(), $custom_classes = false ) {

		$bp_classes = array();

		/* Pages *************************************************************/

		if ( is_front_page() ) {
			$bp_classes[] = 'home-page';
		}

		if ( bp_is_directory() ) {
			$bp_classes[] = 'directory';
		}

		if ( bp_is_single_item() ) {
			$bp_classes[] = 'single-item';
		}

		/* Components ********************************************************/

		if ( ! bp_is_blog_page() ) {
			if ( bp_is_user_profile() )  {
				$bp_classes[] = 'xprofile';
			}

			if ( bp_is_activity_component() ) {
				$bp_classes[] = 'activity';
			}

			if ( bp_is_blogs_component() ) {
				$bp_classes[] = 'blogs';
			}

			if ( bp_is_messages_component() ) {
				$bp_classes[] = 'messages';
			}

			if ( bp_is_friends_component() ) {
				$bp_classes[] = 'friends';
			}

			if ( bp_is_groups_component() ) {
				$bp_classes[] = 'groups';
			}

			if ( bp_is_settings_component()  ) {
				$bp_classes[] = 'settings';
			}

			if ( bp_is_invites_component() ) {
				$bp_classes[] = 'invites';
			}
		}

		/* User **************************************************************/

		if ( bp_is_user() ) {
			$bp_classes[] = 'bp-user';

			// Add current user profile types.
			if ( $member_types = bp_get_member_type( bp_displayed_user_id(), false ) ) {
				foreach( $member_types as $member_type ) {
					$bp_classes[] = sprintf( 'member-type-%s', esc_attr( $member_type ) );
				}
			}
		}

		if ( ! bp_is_directory() ) {
			if ( bp_is_user_blogs() ) {
				$bp_classes[] = 'my-blogs';
			}

			if ( bp_is_user_groups() ) {
				$bp_classes[] = 'my-groups';
			}

			if ( bp_is_user_activity() ) {
				$bp_classes[] = 'my-activity';
			}
		} else {
			if ( bp_get_current_member_type() || ( bp_is_groups_directory() && bp_get_current_group_directory_type() ) ) {
				$bp_classes[] = 'type';
			}
		}

		if ( bp_is_my_profile() ) {
			$bp_classes[] = 'my-account';
		}

		if ( bp_is_user_profile() ) {
			$bp_classes[] = 'my-profile';
		}

		if ( bp_is_user_friends() ) {
			$bp_classes[] = 'my-friends';
		}

		if ( bp_is_user_messages() ) {
			$bp_classes[] = 'my-messages';
		}

		if ( bp_is_user_recent_commments() ) {
			$bp_classes[] = 'recent-comments';
		}

		if ( bp_is_user_recent_posts() ) {
			$bp_classes[] = 'recent-posts';
		}

		if ( bp_is_user_change_avatar() ) {
			$bp_classes[] = 'change-avatar';
		}

		if ( bp_is_user_profile_edit() ) {
			$bp_classes[] = 'profile-edit';
		}

		if ( bp_is_user_friends_activity() ) {
			$bp_classes[] = 'friends-activity';
		}

		if ( bp_is_user_groups_activity() ) {
			$bp_classes[] = 'groups-activity';
		}

		/* Messages **********************************************************/

		if ( bp_is_messages_inbox() ) {
			$bp_classes[] = 'inbox';
		}

		if ( bp_is_messages_compose_screen() ) {
			$bp_classes[] = 'compose';
		}

		if ( bp_is_notices() ) {
			$bp_classes[] = 'notices';
		}

		if ( bp_is_user_friend_requests() ) {
			$bp_classes[] = 'friend-requests';
		}

		if ( bp_is_create_blog() ) {
			$bp_classes[] = 'create-blog';
		}

		/* Groups ************************************************************/

		if ( bp_is_group() ) {
			$bp_classes[] = 'group-' . groups_get_current_group()->slug;

			// Add current group types.
			if ( $group_types = bp_groups_get_group_type( bp_get_current_group_id(), false ) ) {
				foreach ( $group_types as $group_type ) {
					$bp_classes[] = sprintf( 'group-type-%s', esc_attr( $group_type ) );
				}
			}
		}

		if ( bp_is_group_leave() ) {
			$bp_classes[] = 'leave-group';
		}

		if ( bp_is_group_invites() ) {
			$bp_classes[] = 'group-invites';
		}

		if ( bp_is_group_members() ) {
			$bp_classes[] = 'group-members';
		}

		if ( bp_is_group_admin_page() ) {
			$bp_classes[] = 'group-admin';
			$bp_classes[] = bp_get_group_current_admin_tab();
		}

		if ( bp_is_group_create() ) {
			$bp_classes[] = 'group-create';
			$bp_classes[] = bp_get_groups_current_create_step();
		}

		if ( bp_is_group_home() ) {
			$bp_classes[] = 'group-home';
		}

		if ( bp_is_single_activity() ) {
			$bp_classes[] = 'activity-permalink';
		}

		/* Registration ******************************************************/

		if ( bp_is_register_page() ) {
			$bp_classes[] = 'registration';
		}

		if ( bp_is_activation_page() ) {
			$bp_classes[] = 'activation';
		}

		/* Current Component & Action ****************************************/

		if ( ! bp_is_blog_page() ) {
			$bp_classes[] = bp_current_component();
			$bp_classes[] = str_replace(',', ' ', bp_current_action());
		}

		/* Clean up ***********************************************************/

		// Add BuddyPress class if we are within a BuddyPress page.
		if ( ! bp_is_blog_page() ) {
			$bp_classes[] = 'buddypress';
		}

		// Add the theme name/id to the body classes
		$bp_classes[] = 'bp-' . bp_get_theme_compat_id();

		// Merge WP classes with BuddyPress classes and remove any duplicates.
		$classes = array_unique( array_merge( (array) $bp_classes, (array) $wp_classes ) );

		/**
		 * Filters the BuddyPress classes to be added to body_class()
		 *
		 * @since BuddyPress 1.1.0
		 *
		 * @param array $classes        Array of body classes to add.
		 * @param array $bp_classes     Array of BuddyPress-based classes.
		 * @param array $wp_classes     Array of WordPress-based classes.
		 * @param array $custom_classes Array of classes that were passed to get_body_class().
		 */
		return apply_filters( 'bp_get_the_body_class', $classes, $bp_classes, $wp_classes, $custom_classes );
	}

Changelog

Changelog
Version Description
BuddyPress 1.1.0 Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.