The code below assumes that only one tag ( ‘private’ ) has a text associated with it:
function add_tag_text_to_title( $title, $id = null ) {
if ( has_tag( 'private' ) ) {
return $title . ' - Awesome';
} else {
return $title;
}
}
add_filter( 'the_title', 'add_tag_text_to_title', 10, 2 );
If you have more than one tag with text associated with it:
function add_tag_texts_to_title( $title, $id = null ) {
$tag_texts = array (
'tag1' => 'text1',
'tag2' => 'text2',
'tag3' => 'text3'
);
$new_title = $title;
foreach ( $tag_texts as $key => $value ) {
if ( has_tag( $key ) )
$new_title .= ' - ' . $value;
}
return $new_title;
}
add_filter( 'the_title', 'add_tag_texts_to_title', 10, 2 );