📡 You're offline — showing cached content
New version available!
Quick Access
Tutorials WordPress Development Actions and Filters

Actions and Filters

6 min read Quiz at the end
Actions add side effects at hook points; filters transform and return values — core WP extensibility.

Actions vs Filters

# ACTIONS -- side effects, no return value needed
function send_welcome_email($user_id) {
    $user = get_userdata($user_id);
    wp_mail($user->user_email, 'Welcome!', 'Thanks for joining.');
}
add_action('user_register', 'send_welcome_email');

# FILTERS -- transform a value, MUST return it
function add_copyright($content) {
    if (is_single()) {
        $content .= '

© ' . date('Y') . ' My Company

'; } return $content; // MUST return! } add_filter('the_content', 'add_copyright'); # Priority (lower = runs first, default = 10) add_action('init', 'my_function', 5); # Remove hooks remove_action('wp_head', 'wp_generator'); remove_filter('the_content', 'wpautop'); # Key difference: # add_action -- do something at a point # add_filter -- modify something and return it
Topic Quiz · 1 questions

Test your understanding before moving on

1. What must a WordPress filter always do?
💡 Filters must return the modified value — forgetting to return it causes the value to become null.