Reply To: Filtering Title in BuddyPress
Hi Henry – thanks for response. As confirmed by both the Codex (Code Reference) and my successful use of this method in the same installation outside of BuddyPress, $title is indeed an array.
In fact, I tested my function without the if ( bp_is_group() ){ conditional, and the filter works on the pages NOT created/affected by BuddyPress, which confirms BuddyPress is bypassing this filter.
For testing purposes, I modified the function as follows:
// test parameters passed to document_title_parts filter
function test_groups_title( $title ){
print_r( $title );
exit;
}
add_filter('document_title_parts', 'test_groups_title', 10);
And BuddyPress pages output the following array:
Array
(
[title] =>
[site] => My-Website.com
)
Which suggests that BuddyPress is neither supplying data to this array nor utilizing it for the title output.
I did a grep of BuddyPress and bbPress and I am finding calls to the deprecated wp_title() function:
$ grep -r 'wp_title' ../plugins/b*press/*
../plugins/bbpress/includes/core/filters.php:add_filter( 'wp_title', 'bbp_title', 10, 3 );
../plugins/bbpress/readme.txt:* Fix custom wp_title compatibility
../plugins/buddypress/bp-core/bp-core-filters.php: * @see wp_title()
../plugins/buddypress/bp-core/bp-core-filters.php: * @see wp_title()
../plugins/buddypress/bp-core/bp-core-filters.php: * Filters the older 'wp_title' page title for BuddyPress pages.
../plugins/buddypress/bp-core/bp-core-filters.php:add_filter( 'wp_title', 'bp_modify_page_title', 20, 3 );
../plugins/buddypress/bp-core/deprecated/1.5.php: * @deprecated Use wp_title()
../plugins/buddypress/bp-core/deprecated/1.5.php: * Now, just simply use wp_title().
../plugins/buddypress/bp-core/deprecated/1.5.php: * @deprecated Use wp_title()
../plugins/buddypress/bp-core/deprecated/1.5.php: _deprecated_function( __FUNCTION__, '1.5', 'wp_title()' );
../plugins/buddypress/bp-core/deprecated/1.5.php: $title = wp_title( '|', false, 'right' ) . get_bloginfo( 'name', 'display' );
../plugins/buddypress/bp-themes/bp-default/header.php: <title><?php wp_title( '|', true, 'right' ); bloginfo( 'name' ); ?></title>
../plugins/buddypress/bp-themes/bp-default/archive.php: <h3 class="pagetitle"><?php printf( __( 'You are browsing the archive for %1$s.', 'buddypress' ), wp_title( false, false ) ); ?></h3>
I guess this means I can and should hook in to the older (deprecated) wp_title() function? I’m a bit new to BuddyPress and WordPress, so maybe I’m missing something obvious, or barking up the wrong tree here….