Changing How Your WordPress Post Titles Appear: A First Filter Hook Tutorial

wordpress how to filter post title

This Quick Guide covers how to use code to change your WordPress post titles. This is separate from manually changing one or more WordPress post titles, which you can do without code. Instead, it’s the kind of thing you’d want to use to change something about a lot of post titles at once, like adding “(Sale!)” in front of all 200 products in a product category.

This Quick Guide is also an intro to writing your first WordPress filter function, since filters are the best way to change post titles. The filter hook we’ll be hooking onto is called, helpfully, the_title.

Here’s the full video guide to filtering your WordPress post titles:

And here’s a text guide to the same information. In the video above, we’ve changed all post titles on the site to include the word “Hooked: ” This is in the name of making the simplest WordPress filter function example we can. Here’s how we do that in PHP code:

add_filter('the_title', 'wpshout_filter_example');
function wpshout_filter_example($title) {
	return 'Hooked: '.$title;

How the Code Above Changes Your Post Titles

For a fuller explanation of the code above, here’s how it works step-by-step:

  1. We use the add_filter function provided to WordPress that when it “applies” the 'the_title' filter we want our function to be called. That’s the second thing we’re giving it: the name of our function.
  2. Then our function is taking the value passed to it by the 'the_title' filter, that’s the whole next line.
  3. Finally, we added the word “Hooked: ” to the front of the passed value $title and pass it back with the return keyword.

The code we don’t need to write is “what WordPress does with this”: WordPress handles that. Basically, our code takes in each post’s title, modifies it, and hands it back to WordPress to move ahead with. WordPress uses our modified version in the place of the title, and we don’t have to write any more than these four lines. It’s a really powerful system!

There’s a great deal more to know and understand hooks and filters in WordPress well, and our article on them is a great overview of the core distinctions and important details.

Here are some other resources you may love as well:

Learn WordPress Development: The Basic Course

The Best Way to Learn WordPress Development

Get Up and Running Today

Up and Running is our complete “learn WordPress development” course. Now in its updated and expanded Third Edition, it’s helped hundreds of happy buyers learn WordPress development the fast, smart, and thorough way.

Here’s what they have to say:

“I think anyone interested in learning WordPress development NEEDS this course. Watching the videos was like a bunch of lights being turned on.” -Jason, WordPress developer

“Other courses I’ve tried nearly always lack clear explanations for why WordPress does things a certain way, or how things work together. Up and Running does all of this, and everything is explained clearly and in easy-to-understand language.” -Caroline, WordPress freelancer

Happy hacking!

Add a Comment

Your email address will not be published. Required fields are marked *