Show prefix/suffix for posts in a certain category

post-title-suffix

I recently wanted to add a suffix to the post titles on Ellie’s and Jack’s websites to indicate when a post was in the “Videos” category. This is because I added the video after the more tag so it sometimes wouldn’t be apparent that there was a video to watch without any other context.

I created a function which checks whether a post is in the loop (this prevents these suffixes from appearing on menu items, widgets etc.) and in the category in question. If it is, it adds the suffix to the title. Note that this does not change the post title, but instead it merely displays the suffix when viewing the post on the website (or RSS feed etc. – wherever the_title filter is used).

Now when you browse your site, posts in this category will have a suffix ([VIDEO] in this case) added to them:

post-title-suffix

Leave a Reply