Advertisement
Beginner PHP, WordPress Plugin & Theme Development

What are WordPress hooks, specifically actions and filters, and how do they let plugins and themes modify or extend WordPress's default behavior?

Short answer

WordPress hooks provide the primary mechanism through which plugins and themes can modify or extend WordPress's core behavior without needing to directly edit WordPress's own core files, and an action hook lets you run your own custom code at a specific predetermined point…

Save PHP mock interview
Advertisement
AModel answer
WordPress hooks provide the primary mechanism through which plugins and themes can modify or extend WordPress's core behavior without needing to directly edit WordPress's own core files, and an action hook lets you run your own custom code at a specific predetermined point during WordPress's execution, such as right after a new post is published, while a filter hook lets you intercept and modify a specific piece of data as it passes through WordPress, such as changing the exact text of a post's title before it is actually displayed to a visitor.
add_action('publish_post', 'notify_team_of_new_post');

add_filter('the_title', function ($title) {
    return strtoupper($title);
});
Real-world example
A plugin uses an action hook to automatically send an internal team notification whenever a new blog post is published, and separately uses a filter hook to automatically convert every displayed post title to uppercase letters.
Likely follow-ups
  • What is the difference between add_action and add_filter, and how do you know which one to use in a given situation?
  • How do you find a complete list of all the hooks available within WordPress core?
Related topics