Have you ever wanted to add a little specification to your post titles if they were in a certain category. For instance this post. I have it filed under “Quick Tip”. What if I wanted to add the text “Quick Tip:” in front of every post in that category. It’s pretty simple.
[php]
add_filter( ‘the_title’, ‘my_modify_title’, 10, 2 );
function my_modify_title( $title, $id ) {
if( in_category( ‘Quick Tip’, $id ) ) {
$title = ‘Quick Tip: ‘ . $title;
}
return $title;
}
[/php]
Add this code to your site functionality plugin and change it for your particular category and you are all set. I even wrapped the added text in a span in case you wanted to style it to make it stand out.
One thing to keep in mind. You can do an if/else in here to do this for several categories if you like but it certainly works best if you are assigning one category per post. Otherwise it will simply use the first match.
Jo says
Simple and very useful. Thanks!
James Laws says
Thanks for stopping by and commenting. Glad you found it useful.
Excess says
what do you mean by “functionality plugin” tried to insert it into my function.php file but to no avail. Thanks
James Laws says
A functionality is a custom plugin you create to place all your custom code into. It’s much better than putting it in your themes functions.php file because if you ever change themes the plugin is still intact. Here is a quick tutorial on how to go about that.