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

3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
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

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.