The problem with your first approach is that you check conditional tags too early. is_tag
will work only after the $wp_query
is computed, so there is no point in checking it directly in functions.php
file.
And there is one more problem with both approaches – you use wrong conditional tag…
is_tag
checks if a Tag archive page is being displayed… So it’s not what you’re looking for.
And here’s a solution:
function add_something_to_post_title( $title ) {
if ( has_tag( 162 ) ) {
$title="something " . $title;
}
return $title;
}
add_filter( 'the_title', 'add_something_to_post_title' );