WordPress Hooks and Filter | Complete Overview of WordPress hooks

Wordpress custom hooks

Loading

There are hundreds of WordPress hooksโ€”both actions and filtersโ€”and while many are documented officially on developer.wordpress.org, some nuanced use cases and practical insights are often missing or scattered. While itโ€™s impossible to list all WordPress hooks in a single message, Iโ€™ll give you a detailed categorized list of most important and lesser-known hooks, including usage insights and advanced scenarios that are rarely found in one place online.


WordPress Hooks Overview

There are two types of hooks:

  • Actions โ€“ Let you add custom functionality.
  • Filters โ€“ Let you modify data before itโ€™s used or output.

Most Important and Underrated WordPress Hooks (With Usage)

Core Initialization & Request Hooks

HookTypeUsage
initActionFires after WordPress has loaded but before headers are sent. Use to register custom post types, taxonomies, or custom endpoints.
after_setup_themeActionLoad theme support, menus, sidebars. Place add_theme_support() here.
wp_loadedActionFires once WordPress, themes, and plugins are fully loaded. Ideal for conditional redirects.
template_redirectActionUse for redirecting based on templates, like redirecting single post types to a custom template.
parse_requestActionAdvanced URL parsing. Useful for custom routing in REST-like plugins.

Template & Frontend Hooks

HookTypeUsage
wp_headActionUsed to inject meta tags, styles, JavaScript, tracking codes.
wp_footerActionUse for analytics scripts or chat widgets just before </body>.
the_contentFilterModify the main post content (e.g., auto-inserting affiliate links, ads, etc).
the_titleFilterAlter post titles dynamically (e.g., prefix โ€œSponsoredโ€ to specific post categories).
body_classFilterAdd custom body classes based on post type, page slug, or custom logic.

Login & User Management Hooks

HookTypeUsage
wp_loginActionFires on successful login. Useful for custom logging, redirection, or tracking login times.
login_redirectFilterCustomize post-login redirects (e.g., redirect authors to the post list, admins to dashboard).
authenticateFilterValidate login credentials. Add OTP or 2FA here.
user_registerActionFire when a new user registers. Good for sending welcome emails or syncing CRM.
edit_user_profile_updateActionTriggered when a user updates their profile from admin.

WooCommerce Specific Hooks (Lesser-Known)

HookTypeUsage
woocommerce_before_calculate_totalsActionModify cart items before totals calculation (e.g., custom pricing logic).
woocommerce_checkout_update_order_metaActionSave extra checkout fields to the order.
woocommerce_thankyouActionPost-order logicโ€”send API to CRM, show upsell, etc.
woocommerce_product_get_priceFilterDynamically change product prices based on user role, season, or cart contents.

REST API Hooks

HookTypeUsage
rest_api_initActionRegister custom REST routes.
rest_pre_dispatchFilterIntercept all REST API calls before they reach the endpoint. Useful for authentication tweaks.
rest_request_before_callbacksFilterRun custom logic before the endpoint logic runs.
rest_post_dispatchFilterModify the final API responseโ€”good for wrapping it in custom JSON structure.

Editor & Content Related Hooks

HookTypeUsage
register_block_type_argsFilterModify block properties during registration. Add dynamic attributes.
allowed_block_types_allFilterRestrict or allow block types by user role or post type.
enqueue_block_editor_assetsActionLoad custom styles/scripts in Gutenberg editor only.
the_excerptFilterTweak auto-generated excerptsโ€”great for SEO tweaks.

Rare & Powerful Hooks (Advanced Use Cases)

HookTypeHidden Use
shutdownActionLast point before PHP dies. Use to log slow executions or memory usage.
http_api_debugActionDebug external HTTP calls made with wp_remote_get().
pre_get_postsActionModify queries globally or conditionally. Powerful for altering main queries without touching templates.
query_varsFilterAdd custom query vars for custom URL routing.
requestFilterModify request parsing earlyโ€”great for multilingual or custom routing logic.
sanitize_file_nameFilterModify filenames on upload. E.g., enforce lowercase or remove special characters.
upload_mimesFilterAllow new file types like .svg, .webp.
wp_mailFilterModify the contents of all outgoing emails.
script_loader_tagFilterAdd attributes like defer, async, or even type="module" to enqueued scripts.

Hook Usage Pattern (Best Practice)

// Action example
add_action('init', 'register_my_post_type');
function register_my_post_type() {
    register_post_type('book', [...]);
}

// Filter example
add_filter('the_title', 'custom_title_append');
function custom_title_append($title) {
    if (is_singular('book')) {
        $title .= ' ๐Ÿ“š';
    }
    return $title;
}

Bonus: Not on Most Lists

  1. rest_authentication_errors โ€“ Useful for overriding default auth errors, especially in headless WordPress.
  2. get_search_form โ€“ Allows you to completely override the output of the default search form.
  3. wp_get_attachment_image_attributes โ€“ Add custom attributes like loading="lazy" or decoding="async" for SEO.

If youโ€™re planning to revamp your online presence, donโ€™t miss exploring ourย website designing servicesย and customย website developmentย solutions tailored to your business needs.

About Post Author