Filter
uncanny-automator
bbp_get_topic_title
Filters the topic title before it is displayed, allowing for modification based on context or meta values.
add_filter( 'bbp_get_topic_title', $callback, 10, 2 );
Description
Filters the BuddyBoss topic title, allowing developers to modify or replace the topic's displayed title. This is useful for custom title formatting or integrating with other BuddyBoss features. The hook receives the current topic title and its meta value.
Usage
add_filter( 'bbp_get_topic_title', 'your_function_name', 10, 2 );
Parameters
-
$title(mixed) - This parameter contains the current title of the topic being filtered.
-
$meta_value(mixed) - This parameter contains the current title of the topic being filtered, which can be modified by the filter.
Return Value
The filtered value.
Examples
/**
* Filters the topic title to append a custom string if the topic belongs to a specific forum.
*
* @param string $title The original topic title.
* @param int $topic_id The ID of the topic.
* @return string The modified topic title.
*/
function my_custom_bbp_topic_title_suffix( $title, $topic_id ) {
// Check if the topic belongs to a specific forum (replace 123 with your forum ID)
$specific_forum_id = 123;
$topic_forum_id = bbp_get_topic_forum_id( $topic_id );
if ( $topic_forum_id === $specific_forum_id ) {
// Append a custom string to the title for topics in the specific forum
$title .= ' [Special Topic]';
}
return $title;
}
add_filter( 'bbp_get_topic_title', 'my_custom_bbp_topic_title_suffix', 10, 2 );
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
src/integrations/buddyboss/tokens/bdb-tokens.php:310
if ( ! empty( $meta_value ) ) {
if ( 'BDBTOPICID' === $pieces[2] ) {
$value = $meta_value;
} elseif ( 'BDBTOPICTITLE' === $pieces[2] ) {
$title = get_the_title( $meta_value );
$value = apply_filters( 'bbp_get_topic_title', $title, $meta_value );
} elseif ( 'BDBTOPICURL' === $pieces[2] ) {
$topic_permalink = get_permalink( $meta_value );
$value = apply_filters( 'bbp_get_topic_permalink', $topic_permalink, $meta_value );
} elseif ( 'BDBTOPICCONTENT' === $pieces[2] ) {
$content = get_post_field( 'post_content', $meta_value );
$value = apply_filters( 'bbp_get_topic_content', $content, $meta_value );
}