WordPress Hooks and Filter | Complete Overview of WordPress hooks
2 months ago
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
Hook
Type
Usage
init
Action
Fires after WordPress has loaded but before headers are sent. Use to register custom post types, taxonomies, or custom endpoints.
after_setup_theme
Action
Load theme support, menus, sidebars. Place add_theme_support() here.
wp_loaded
Action
Fires once WordPress, themes, and plugins are fully loaded. Ideal for conditional redirects.
template_redirect
Action
Use for redirecting based on templates, like redirecting single post types to a custom template.
parse_request
Action
Advanced URL parsing. Useful for custom routing in REST-like plugins.
Template & Frontend Hooks
Hook
Type
Usage
wp_head
Action
Used to inject meta tags, styles, JavaScript, tracking codes.
wp_footer
Action
Use for analytics scripts or chat widgets just before </body>.
the_content
Filter
Modify the main post content (e.g., auto-inserting affiliate links, ads, etc).
the_title
Filter
Alter post titles dynamically (e.g., prefix โSponsoredโ to specific post categories).
body_class
Filter
Add custom body classes based on post type, page slug, or custom logic.
Login & User Management Hooks
Hook
Type
Usage
wp_login
Action
Fires on successful login. Useful for custom logging, redirection, or tracking login times.
login_redirect
Filter
Customize post-login redirects (e.g., redirect authors to the post list, admins to dashboard).
authenticate
Filter
Validate login credentials. Add OTP or 2FA here.
user_register
Action
Fire when a new user registers. Good for sending welcome emails or syncing CRM.
edit_user_profile_update
Action
Triggered when a user updates their profile from admin.
WooCommerce Specific Hooks (Lesser-Known)
Hook
Type
Usage
woocommerce_before_calculate_totals
Action
Modify cart items before totals calculation (e.g., custom pricing logic).
woocommerce_checkout_update_order_meta
Action
Save extra checkout fields to the order.
woocommerce_thankyou
Action
Post-order logicโsend API to CRM, show upsell, etc.
woocommerce_product_get_price
Filter
Dynamically change product prices based on user role, season, or cart contents.
REST API Hooks
Hook
Type
Usage
rest_api_init
Action
Register custom REST routes.
rest_pre_dispatch
Filter
Intercept all REST API calls before they reach the endpoint. Useful for authentication tweaks.
rest_request_before_callbacks
Filter
Run custom logic before the endpoint logic runs.
rest_post_dispatch
Filter
Modify the final API responseโgood for wrapping it in custom JSON structure.
Editor & Content Related Hooks
Hook
Type
Usage
register_block_type_args
Filter
Modify block properties during registration. Add dynamic attributes.
allowed_block_types_all
Filter
Restrict or allow block types by user role or post type.
enqueue_block_editor_assets
Action
Load custom styles/scripts in Gutenberg editor only.
the_excerpt
Filter
Tweak auto-generated excerptsโgreat for SEO tweaks.
Rare & Powerful Hooks (Advanced Use Cases)
Hook
Type
Hidden Use
shutdown
Action
Last point before PHP dies. Use to log slow executions or memory usage.
http_api_debug
Action
Debug external HTTP calls made with wp_remote_get().
pre_get_posts
Action
Modify queries globally or conditionally. Powerful for altering main queries without touching templates.
query_vars
Filter
Add custom query vars for custom URL routing.
request
Filter
Modify request parsing earlyโgreat for multilingual or custom routing logic.
sanitize_file_name
Filter
Modify filenames on upload. E.g., enforce lowercase or remove special characters.
upload_mimes
Filter
Allow new file types like .svg, .webp.
wp_mail
Filter
Modify the contents of all outgoing emails.
script_loader_tag
Filter
Add 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
rest_authentication_errors โ Useful for overriding default auth errors, especially in headless WordPress.
get_search_form โ Allows you to completely override the output of the default search form.
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.