{"id":1387,"date":"2025-05-15T05:28:55","date_gmt":"2025-05-15T05:28:55","guid":{"rendered":"https:\/\/www.appfinz.com\/blogs\/?p=1387"},"modified":"2025-05-15T05:28:56","modified_gmt":"2025-05-15T05:28:56","slug":"wordpress-hooks-and-filter-complete-overview-of-wordpress-hooks","status":"publish","type":"post","link":"https:\/\/www.appfinz.com\/blogs\/wordpress-hooks-and-filter-complete-overview-of-wordpress-hooks\/","title":{"rendered":"WordPress Hooks and Filter | Complete Overview of WordPress hooks"},"content":{"rendered":"\n<p>There are <strong>hundreds of WordPress hooks<\/strong>\u2014both <strong>actions<\/strong> and <strong>filters<\/strong>\u2014and while many are documented officially on <a>developer.wordpress.org<\/a>, some nuanced use cases and <strong>practical insights<\/strong> are often missing or scattered. While it\u2019s impossible to list <em>all<\/em> WordPress hooks in a single message, I\u2019ll give you a <strong>detailed categorized list<\/strong> of <strong>most important and lesser-known hooks<\/strong>, including <strong>usage insights and advanced scenarios<\/strong> that are rarely found in one place online.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">WordPress Hooks Overview<\/h2>\n\n\n\n<p>There are two types of hooks:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Actions<\/strong> \u2013 Let you add custom functionality.<\/li>\n\n\n\n<li><strong>Filters<\/strong> \u2013 Let you modify data before it\u2019s used or output.<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Most Important and Underrated WordPress Hooks (With Usage)<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Core Initialization &amp; Request Hooks<\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Hook<\/th><th>Type<\/th><th>Usage<\/th><\/tr><\/thead><tbody><tr><td><code>init<\/code><\/td><td>Action<\/td><td>Fires after WordPress has loaded but before headers are sent. Use to register custom post types, taxonomies, or custom endpoints.<\/td><\/tr><tr><td><code>after_setup_theme<\/code><\/td><td>Action<\/td><td>Load theme support, menus, sidebars. Place <code>add_theme_support()<\/code> here.<\/td><\/tr><tr><td><code>wp_loaded<\/code><\/td><td>Action<\/td><td>Fires once WordPress, themes, and plugins are fully loaded. Ideal for conditional redirects.<\/td><\/tr><tr><td><code>template_redirect<\/code><\/td><td>Action<\/td><td>Use for redirecting based on templates, like redirecting single post types to a custom template.<\/td><\/tr><tr><td><code>parse_request<\/code><\/td><td>Action<\/td><td>Advanced URL parsing. Useful for custom routing in REST-like plugins.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Template &amp; Frontend Hooks<\/strong><\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Hook<\/th><th>Type<\/th><th>Usage<\/th><\/tr><\/thead><tbody><tr><td><code>wp_head<\/code><\/td><td>Action<\/td><td>Used to inject meta tags, styles, JavaScript, tracking codes.<\/td><\/tr><tr><td><code>wp_footer<\/code><\/td><td>Action<\/td><td>Use for analytics scripts or chat widgets just before <code>&lt;\/body&gt;<\/code>.<\/td><\/tr><tr><td><code>the_content<\/code><\/td><td>Filter<\/td><td>Modify the main post content (e.g., auto-inserting affiliate links, ads, etc).<\/td><\/tr><tr><td><code>the_title<\/code><\/td><td>Filter<\/td><td>Alter post titles dynamically (e.g., prefix \u201cSponsored\u201d to specific post categories).<\/td><\/tr><tr><td><code>body_class<\/code><\/td><td>Filter<\/td><td>Add custom body classes based on post type, page slug, or custom logic.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Login &amp; User Management Hooks<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Hook<\/th><th>Type<\/th><th>Usage<\/th><\/tr><\/thead><tbody><tr><td><code>wp_login<\/code><\/td><td>Action<\/td><td>Fires on successful login. Useful for custom logging, redirection, or tracking login times.<\/td><\/tr><tr><td><code>login_redirect<\/code><\/td><td>Filter<\/td><td>Customize post-login redirects (e.g., redirect authors to the post list, admins to dashboard).<\/td><\/tr><tr><td><code>authenticate<\/code><\/td><td>Filter<\/td><td>Validate login credentials. Add OTP or 2FA here.<\/td><\/tr><tr><td><code>user_register<\/code><\/td><td>Action<\/td><td>Fire when a new user registers. Good for sending welcome emails or syncing CRM.<\/td><\/tr><tr><td><code>edit_user_profile_update<\/code><\/td><td>Action<\/td><td>Triggered when a user updates their profile from admin.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">WooCommerce Specific Hooks (Lesser-Known)<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Hook<\/th><th>Type<\/th><th>Usage<\/th><\/tr><\/thead><tbody><tr><td><code>woocommerce_before_calculate_totals<\/code><\/td><td>Action<\/td><td>Modify cart items before totals calculation (e.g., custom pricing logic).<\/td><\/tr><tr><td><code>woocommerce_checkout_update_order_meta<\/code><\/td><td>Action<\/td><td>Save extra checkout fields to the order.<\/td><\/tr><tr><td><code>woocommerce_thankyou<\/code><\/td><td>Action<\/td><td>Post-order logic\u2014send API to CRM, show upsell, etc.<\/td><\/tr><tr><td><code>woocommerce_product_get_price<\/code><\/td><td>Filter<\/td><td>Dynamically change product prices based on user role, season, or cart contents.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">REST API Hooks<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Hook<\/th><th>Type<\/th><th>Usage<\/th><\/tr><\/thead><tbody><tr><td><code>rest_api_init<\/code><\/td><td>Action<\/td><td>Register custom REST routes.<\/td><\/tr><tr><td><code>rest_pre_dispatch<\/code><\/td><td>Filter<\/td><td>Intercept all REST API calls before they reach the endpoint. Useful for authentication tweaks.<\/td><\/tr><tr><td><code>rest_request_before_callbacks<\/code><\/td><td>Filter<\/td><td>Run custom logic before the endpoint logic runs.<\/td><\/tr><tr><td><code>rest_post_dispatch<\/code><\/td><td>Filter<\/td><td>Modify the final API response\u2014good for wrapping it in custom JSON structure.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Editor &amp; Content Related Hooks<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Hook<\/th><th>Type<\/th><th>Usage<\/th><\/tr><\/thead><tbody><tr><td><code>register_block_type_args<\/code><\/td><td>Filter<\/td><td>Modify block properties during registration. Add dynamic attributes.<\/td><\/tr><tr><td><code>allowed_block_types_all<\/code><\/td><td>Filter<\/td><td>Restrict or allow block types by user role or post type.<\/td><\/tr><tr><td><code>enqueue_block_editor_assets<\/code><\/td><td>Action<\/td><td>Load custom styles\/scripts in Gutenberg editor only.<\/td><\/tr><tr><td><code>the_excerpt<\/code><\/td><td>Filter<\/td><td>Tweak auto-generated excerpts\u2014great for SEO tweaks.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Rare &amp; Powerful Hooks (Advanced Use Cases)<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Hook<\/th><th>Type<\/th><th>Hidden Use<\/th><\/tr><\/thead><tbody><tr><td><code>shutdown<\/code><\/td><td>Action<\/td><td>Last point before PHP dies. Use to log slow executions or memory usage.<\/td><\/tr><tr><td><code>http_api_debug<\/code><\/td><td>Action<\/td><td>Debug external HTTP calls made with <code>wp_remote_get()<\/code>.<\/td><\/tr><tr><td><code>pre_get_posts<\/code><\/td><td>Action<\/td><td>Modify queries globally or conditionally. Powerful for altering main queries without touching templates.<\/td><\/tr><tr><td><code>query_vars<\/code><\/td><td>Filter<\/td><td>Add custom query vars for custom URL routing.<\/td><\/tr><tr><td><code>request<\/code><\/td><td>Filter<\/td><td>Modify request parsing early\u2014great for multilingual or custom routing logic.<\/td><\/tr><tr><td><code>sanitize_file_name<\/code><\/td><td>Filter<\/td><td>Modify filenames on upload. E.g., enforce lowercase or remove special characters.<\/td><\/tr><tr><td><code>upload_mimes<\/code><\/td><td>Filter<\/td><td>Allow new file types like <code>.svg<\/code>, <code>.webp<\/code>.<\/td><\/tr><tr><td><code>wp_mail<\/code><\/td><td>Filter<\/td><td>Modify the contents of all outgoing emails.<\/td><\/tr><tr><td><code>script_loader_tag<\/code><\/td><td>Filter<\/td><td>Add attributes like <code>defer<\/code>, <code>async<\/code>, or even <code>type=\"module\"<\/code> to enqueued scripts.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Hook Usage Pattern (Best Practice)<\/h2>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text\/x-php&quot;,&quot;theme&quot;:&quot;midnight&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:false,&quot;fileName&quot;:&quot;PHP&quot;,&quot;language&quot;:&quot;PHP&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;php&quot;}\">\/\/ Action example\nadd_action('init', 'register_my_post_type');\nfunction register_my_post_type() {\n    register_post_type('book', [...]);\n}\n\n\/\/ Filter example\nadd_filter('the_title', 'custom_title_append');\nfunction custom_title_append($title) {\n    if (is_singular('book')) {\n        $title .= ' \ud83d\udcda';\n    }\n    return $title;\n}\n<\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Bonus: Not on Most Lists<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong><code>rest_authentication_errors<\/code><\/strong> \u2013 Useful for overriding default auth errors, especially in headless WordPress.<\/li>\n\n\n\n<li><strong><code>get_search_form<\/code><\/strong> \u2013 Allows you to completely override the output of the default search form.<\/li>\n\n\n\n<li><strong><code>wp_get_attachment_image_attributes<\/code><\/strong> \u2013 Add custom attributes like <code>loading=\"lazy\"<\/code> or <code>decoding=\"async\"<\/code> for SEO.<\/li>\n<\/ol>\n\n\n\n<p class=\"has-background\" style=\"background-color:#e6eef4\">If you\u2019re planning to revamp your online presence, don\u2019t miss exploring our\u00a0<a href=\"https:\/\/www.appfinz.com\/website-designing-company-in-delhi\"><strong>website designing services<\/strong><\/a>\u00a0and custom\u00a0<strong><a href=\"https:\/\/www.appfinz.com\/website-development-company-in-delhi\">website development<\/a><\/strong>\u00a0solutions tailored to your business needs.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>There are hundreds of WordPress hooks\u2014both actions and filters\u2014and while many are documented officially on<\/p>\n","protected":false},"author":1,"featured_media":1388,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1387","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php"],"_links":{"self":[{"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/posts\/1387","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/comments?post=1387"}],"version-history":[{"count":1,"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/posts\/1387\/revisions"}],"predecessor-version":[{"id":1389,"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/posts\/1387\/revisions\/1389"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/media\/1388"}],"wp:attachment":[{"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/media?parent=1387"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/categories?post=1387"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/tags?post=1387"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}