Change title tag for Buddypress single page activities

Here’s a small code snippet to change Buddypress’ single activity page title tag.

This is especially helpful when you want better SEO for your Buddypress website. Implementing it will stop search engines, like Google, fussing over your otherwise duplicate single activity titles.

Hook into bp_modify_document_title_parts and change the title to whatever dynamic text you’d like. Implement the code snippet in your theme’s functions.php or bp-custom.php file to activate it.

bp-custom.php

function add_single_activity_to_title( $title ) {
    global $bp;
	// are we on a single activity page?
	if ( bp_is_active( 'activity' ) && bp_is_single_activity() ) {
	    // insert new title
		$title['title'] = sprintf( 'Your new title');
	}
    return $title;
}
add_filter( 'bp_modify_document_title_parts', 'add_single_activity_to_title', 100, 3 );