bp_get_title_parts( string $seplocation = 'right' )
Get the title parts of the BuddyPress displayed page
Description
Parameters
- $seplocation
-
(Optional) Location for the separator.
Default value: 'right'
Return
(array) the title parts
Source
File: bp-core/bp-core-template.php
function bp_get_title_parts( $seplocation = 'right' ) {
$bp = buddypress();
// Defaults to an empty array.
$bp_title_parts = array();
// If this is not a BP page, return the empty array.
if ( bp_is_blog_page() ) {
return $bp_title_parts;
}
// If this is a 404, return the empty array.
if ( is_404() ) {
return $bp_title_parts;
}
// If this is the front page of the site, return the empty array.
if ( is_front_page() || is_home() ) {
return $bp_title_parts;
}
// Return the empty array if not a BuddyPress page.
if ( ! is_buddypress() ) {
return $bp_title_parts;
}
// Now we can build the BP Title Parts
// Is there a displayed user, and do they have a name?
$displayed_user_name = bp_get_displayed_user_fullname();
// Displayed user.
if ( ! empty( $displayed_user_name ) && ! is_404() ) {
// Get the component's ID to try and get its name.
$component_id = $component_name = bp_current_component();
// Set empty subnav name.
$component_subnav_name = '';
if ( ! empty( $bp->members->nav ) ) {
$primary_nav_item = $bp->members->nav->get_primary( array( 'slug' => $component_id ), false );
$primary_nav_item = reset( $primary_nav_item );
}
// Use the component nav name.
if ( ! empty( $primary_nav_item->name ) ) {
$component_name = _bp_strip_spans_from_title( $primary_nav_item->name );
// Fall back on the component ID.
} elseif ( ! empty( $bp->{$component_id}->id ) ) {
$component_name = ucwords( $bp->{$component_id}->id );
}
if ( ! empty( $bp->members->nav ) ) {
$secondary_nav_item = $bp->members->nav->get_secondary( array(
'parent_slug' => $component_id,
'slug' => bp_current_action()
), false );
if ( $secondary_nav_item ) {
$secondary_nav_item = reset( $secondary_nav_item );
}
}
// Append action name if we're on a member component sub-page.
if ( ! empty( $secondary_nav_item->name ) && ! empty( $bp->canonical_stack['action'] ) ) {
$component_subnav_name = $secondary_nav_item->name;
}
// If on the user profile's landing page, just use the fullname.
if ( bp_is_current_component( $bp->default_component ) && ( bp_get_requested_url() === bp_displayed_user_domain() ) ) {
$bp_title_parts[] = $displayed_user_name;
// Use component name on member pages.
} else {
$bp_title_parts = array_merge( $bp_title_parts, array_map( 'strip_tags', array(
$displayed_user_name,
$component_name,
) ) );
// If we have a subnav name, add it separately for localization.
if ( ! empty( $component_subnav_name ) ) {
$bp_title_parts[] = strip_tags( $component_subnav_name );
}
}
// A single item from a component other than Members.
} elseif ( bp_is_single_item() ) {
$component_id = bp_current_component();
if ( ! empty( $bp->{$component_id}->nav ) ) {
$secondary_nav_item = $bp->{$component_id}->nav->get_secondary( array(
'parent_slug' => bp_current_item(),
'slug' => bp_current_action()
), false );
if ( $secondary_nav_item ) {
$secondary_nav_item = reset( $secondary_nav_item );
}
}
$single_item_subnav = '';
if ( ! empty( $secondary_nav_item->name ) ) {
$single_item_subnav = $secondary_nav_item->name;
}
$bp_title_parts = array( $bp->bp_options_title, $single_item_subnav );
// An index or directory.
} elseif ( bp_is_directory() ) {
$current_component = bp_current_component();
// No current component (when does this happen?).
$bp_title_parts = array( __( 'Directory', 'buddyboss' ) );
if ( ! empty( $current_component ) ) {
$bp_title_parts = array( bp_get_directory_title( $current_component ) );
}
// Sign up page.
} elseif ( bp_is_register_page() ) {
$bp_title_parts = array( __( 'Create an Account', 'buddyboss' ) );
// Activation page.
} elseif ( bp_is_activation_page() ) {
$bp_title_parts = array( __( 'Activate Your Account', 'buddyboss' ) );
// Group creation page.
} elseif ( bp_is_group_create() ) {
$bp_title_parts = array( __( 'Create a Group', 'buddyboss' ) );
// Blog creation page.
} elseif ( bp_is_create_blog() ) {
$bp_title_parts = array( __( 'Create a Site', 'buddyboss' ) );
}
// Strip spans.
$bp_title_parts = array_map( '_bp_strip_spans_from_title', $bp_title_parts );
// Sep on right, so reverse the order.
if ( 'right' === $seplocation ) {
$bp_title_parts = array_reverse( $bp_title_parts );
}
/**
* Filter BuddyPress title parts before joining.
*
* @since BuddyPress 2.4.3
*
* @param array $bp_title_parts Current BuddyPress title parts.
* @return array
*/
return (array) apply_filters( 'bp_get_title_parts', $bp_title_parts );
}
Changelog
| Version | Description |
|---|---|
| BuddyPress 2.4.3 | 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.