Hooks + Filters – WordPress

WordPress Hooks Database

https://adambrown.info/p/wp_hooks/
What are hooks? WordPress hooks allow you (via a plugin) to change WordPress’s behavior without editing any core files. This database automatically scans each WP build for apply_filters(), apply_filters_ref_array(), do_action(), and do_action_ref_array to identify all the hooks available in each WP build and show them in context.

WordPress Hooks / Filters breakdown

https://codex.wordpress.org/Plugin_API/Action_Reference

https://codex.wordpress.org/Plugin_API/Filter_Reference

Add a Hook after < body > or anywhere


adding hook after body – they really need to add one to wordpress core
https://core.trac.wordpress.org/ticket/12563 – discussion of building that tag
https://make.wordpress.org/core/2019/04/24/miscellaneous-developer-updates-in-5-2/
Bundled Theme: trigger a new wp_body_open action immediately after the opening body tag.
  • Enables inserting (asynchronous) JavaScript right after the opening body tag.
  • Add a wp_body_open helper function that triggers the wp_body_open action.
  • Call wp_body_open in core themes immediately after the opening body tag.

<?php
if ( ! function_exists( 'wp_body_open' ) ) {
        function wp_body_open() {
                do_action( 'wp_body_open' );
        }
}

https://www.beliefmedia.com.au/wordpress-hook-after-body-tag

body_class – simple hook example

https://developer.wordpress.org/reference/hooks/body_class/
https://codex.wordpress.org/Plugin_API/Filter_Reference/body_class








Storefront Hooks: Actions and filters




Note: This is a Developer level doc. If you are unfamiliar with code/templates and resolving potential conflicts, select a  for assistance. We are unable to provide support for customizations under our  .

This document lists the Actions and Filters which are available within the Storefront theme. For a full list of template actions which add the default content in Storefront, you can find a comprehensive list of these within the file/storefront/inc/storefront-template-hooks.php inside the theme folder.

Examples ↑ Back to top

To get familiar with the Storefront hooks it might be good to have a look at some tutorials:

Actions reference guide ↑ Back to top

All available add_action() functions used on the Storefront theme are listed below. To add content before an existing action, you can adjust the ordering position by decreasing the actions priority numerically. To add content after and existing action, you would then increase the action priority. You can read more about add_action() and what parameters can be used on the WordPress Developer Resources site here.

General ↑ Back to top

  • storefront_before_site – Executed after opening <body> tag
  • storefront_before_content – Executed before opening <div id="content"> tag
  • storefront_content_top – Executed after opening <div id="content"> tag

Header ↑ Back to top

  • storefront_before_header – Executed after <div id="page"> tag
  • storefront_header – Executed inside <div class="col-full"> of the <header id="masthead"> tag

Homepage ↑ Back to top

  • storefront_homepage – Executed inside <div class="col-full"> of the homepage content section

Product categories

  • storefront_homepage_before_product_categories – Executed before the <section class="storefront-product-categories"> homepage section
  • storefront_homepage_after_product_categories_title` – Executed after the <h2 class="section-title"> product categories section title
  • storefront_homepage_after_product_categories – Executed after the <section class="storefront-product-categories"> homepage section

Recent products

  • storefront_homepage_before_recent_products – Executed before the <section class="storefront-recent-products"> homepage section
  • storefront_homepage_after_recent_products_title – Executed after the <h2 class="section-title"> recent products section title
  • storefront_homepage_after_recent_products – Executed after the <section class="storefront-recent-products"> homepage section
  • storefront_homepage_before_featured_products – Executed before the <section class="storefront-featured-products"> homepage section
  • storefront_homepage_after_featured_products_title – Executed after the <h2 class="section-title"> featured products section title
  • storefront_homepage_after_featured_products – Executed after the <section class="storefront-featured-products"> homepage section
  • storefront_homepage_before_popular_products – Executed before the <section class="storefront-popular-products"> homepage section
  • storefront_homepage_after_popular_products_title – Executed after the <h2 class="section-title"> popular products section title
  • storefront_homepage_after_popular_products – Executed after the <section class="storefront-popular-products"> homepage section

On sale products

  • storefront_homepage_before_on_sale_products – Executed before the <section class="storefront-on-sale-products"> homepage section
  • storefront_homepage_after_on_sale_products_title – Executed after the <h2 class="section-title"> on-sale products section title
  • storefront_homepage_after_on_sale_products – Executed after the <section class="storefront-on-sale-products"> homepage section

Best-selling products

  • storefront_homepage_before_best_selling_products – Executed before the <section class="storefront-best-selling-products"> homepage section
  • storefront_homepage_after_best_selling_products_title – Executed after the <h2 class="section-title"> best-selling products section title
  • storefront_homepage_after_best_selling_products – Executed after the <section class="storefront-best-selling-products"> homepage section

Blog archive page ↑ Back to top

  • storefront_loop_before – Executed before all posts on blog archive
  • storefront_loop_post – Executed before each post on blog archive
  • storefront_post_content_before – Executed before the content of each post on blog archive
  • storefront_post_content_after – Executed after the content of each post on blog archive

General page ↑ Back to top

  • storefront_page_before – Executed after the `<main id=”main”>` tag on single pages
  • storefront_page – Executed after the opening `<div id=”post-…”>` tag on single pages
  • storefront_page_after – Executed at the end of the `<div id=”post-…”>` tag on single pages

Single post ↑ Back to top

  • storefront_single_post_before – Executed after the opening <main id="main"> tag on single blog posts
  • storefront_single_post_top – Executed after the opening <div id="post-..."> tag on single posts
  • storefront_single_post – Executed immediately after storefront_single_post_top hook to show post content
  • storefront_single_post_bottom – Executed before the closing <div id="post-..."> tag on single posts
  • storefront_single_post_after – Executed before the closing <main id="main"> tag on single blog posts

Sidebar ↑ Back to top

  • storefront_sidebar – Executed on all pages containing a sidebar, provided widgets are present

Footer ↑ Back to top

  • storefront_before_footer – Executed before <footer id="colophon"> tag
  • storefront_footer – Executed before closing <footer id="colophon"> tag
  • storefront_after_footer – Executed after closing <footer id="colophon"> tag

Filters reference guide ↑ Back to top

This document lists some of the most commonly used filters which are available within the Storefront theme. You can read more about add_filter() and what parameters can be used on the WordPress Developer Resources site here

Comments ↑ Back to top

File: comments.php
  • storefront_comment_form_args – filter the comment reply title HTML before and after

Storefront template functions ↑ Back to top

File: /inc/storefront-template-functions.php
  • storefront_menu_toggle_text – filter the responsive menu toggle text

Homepage

Product categories
  • storefront_product_categories_args – filter the homepage product category arguments
  • storefront_product_categories_shortcode_args – filter the homepage product category shortcode arguments
Recent products
  • storefront_recent_products_args – filter the homepage recent products arguments
  • storefront_recent_products_shortcode_args – filter the homepage recent products shortcode arguments
Featured products
  • storefront_featured_products_args – filter the homepage featured products arguments.
  • storefront_featured_products_shortcode_args – filter the homepage featured products shortcode arguments.
Popular products
  • storefront_popular_products_args – filter the homepage popular products arguments.
  • storefront_popular_products_shortcode_args – filter the homepage popular products shortcode arguments.
On sale products
  • storefront_on_sale_products_args – filter the homepage on sale products arguments.
  • storefront_on_sale_products_shortcode_args – filter the homepage on sale products shortcode arguments
Best-selling products
  • storefront_best_selling_products_args – filter the homepage best selling products arguments
  • storefront_best_selling_products_shortcode_args – filter the homepage best selling products shortcode arguments

Single post

  • storefront_single_post_posted_on_html – filter the single posted on details
  • storefront_footer_widget_rows – filter number of footer widget rows (default: 1)
  • storefront_footer_widget_columns – filter number of footer widget columns (default: 4)
  • storefront_copyright_text – filter the footer copyright text
  • storefront_credit_link – filter the footer credit link

Storefront functions ↑ Back to top

File: /inc/storefront-functions.php
  • storefront_header_styles – filter the header styles
  • storefront_homepage_content_styles – filter the homepage content styles

Storefront classes ↑ Back to top

File: /inc/class-storefront.php
  • storefront_custom_background_args – filter the default background arguments
  • storefront_default_background_color – filter the default site background color
  • storefront_sidebar_args – filter the default sidebar arguments
  • storefront_google_font_families – filter default Google Font families
  • storefront_navigation_markup_template – filter the output markup of the navigation.

WooCommerce template functions ↑ Back to top

File: /woocommerce/storefront-woocommerce-template-functions.php
  • storefront_upsells_columns – filter the upsell columns (default: 3)
  • storefront_loop_columns – filter the default product loop display (default: 3)
  • storefront_handheld_footer_bar_links – filter handheld footer bar links

WooCommerce classes ↑ Back to top

File: /woocommerce/class-storefront-woocommerce.php
  • storefront_related_products_args – filter related products arguments
  • storefront_product_thumbnail_columns – filter product thumbnail columns (default: 4)
  • storefront_products_per_page – filter products per page on product categories.

Additional resources ↑ Back to top

For additional resources on Storefront development, please refer to the following:
        <div class="related-docs docs-listing single"><h2>Relevant Links</h2><ul class="recommended-docs"><li><h4><a href="http://docs.woothemes.com/document/installing-a-woo-theme/">Installing Your Theme</a></h4></li><li><h4><a href="http://support.woothemes.com/entries/23060481-How-to-update-theme-to-new-version">How to Update Your Theme</a></h4></li><li><h4><a href="http://www.woothemes.com/theme-demo-content/">Download Theme Demo Content</a></h4></li><li><h4><a href="http://docs.woothemes.com/document/docs-theme-options/">Theme Options</a></h4></li><li><h4><a href="http://docs.woothemes.com/document/shortcodes/">Shortcodes</a></h4></li><li><h4><a href="http://docs.woothemes.com/document/docs-menus/">Menus</a></h4></li><li><h4><a href="http://docs.woothemes.com/document/adding-widgets/">Adding Widgets</a></h4></li><li><h4><a href="http://docs.woothemes.com/document/page-templates/">Page Templates</a></h4></li><li><h4><a href="http://docs.woothemes.com/document/features-plugin/">Features Plugin</a></h4></li><li><h4><a href="http://docs.woothemes.com/document/testimonials-plugin/">Testimonials Plugin</a></h4></li><li><h4><a href="http://docs.woothemes.com/document/featured-images/">Featured Images</a></h4></li><li><h4><a href="https://support.woothemes.com/hc/en-us/articles/203106397-How-to-remove-Designed-by-WooThemes-from-footer">Remove WooThemes Footer Credit</a></h4></li><li><h4><a href="https://support.woothemes.com/hc/en-us/articles/203105957-Customizing-your-theme-with-Firebug">Edit Theme CSS with Firebug</a></h4></li><li><h4><a href="http://woothemes.zendesk.com/entries/22521633-How-to-translate-a-theme-or-plugin">Translate your theme</a></h4></li><li><h4><a href="https://support.woothemes.com/hc/en-us/articles/202881643-Using-WooThemes-Support-Resources">Using WooThemes Support Resources</a></h4></li></ul></div>       
Scroll to Top