In WordPress, add_filter() says: “When this value goes by, let me change it.” A hook that passes a value along so you can change it is called a filter.
WordPress calls apply_filters() on values such as post content, titles, and excerpt length. Each function you add with add_filter() receives the value, may change it, and must return it. The final value is what WordPress uses.
Syntax
Give it the hook name and the name of your function. The function must return a value.
The 2 at the end tells WordPress to pass two values: the title and the post ID.
Sticky posts get Featured: in front of the title.
Other posts are returned without any change.
Frequently Asked Questions
It attaches your function to a filter hook. When WordPress runs apply_filters() on that hook, your function receives the value, changes it, and returns it.
add_action() runs code at a moment and ignores any return value. add_filter() changes a value and the function must return it.
The value becomes empty (null). A post may show no content or a blank title. Always end your filter function with return.
Yes. They run one after another, ordered by priority. Each one gets the value left by the previous one.
the_content, the_title, excerpt_length, excerpt_more, and body_class are easy places to start.