(855)-537-2266 sales@kerbco.com

WordPress Hooks are the real power and the magic of WordPress. They allow us to customize a WordPress site according to our needs. Of course, without modifying the WordPress core files. This can be done by creating custom themes and plugins.

There are two major types of hooks:

The following examples use the array callable syntax for the callback function. In this case, the callback function is a method of the plugin PHP Class. So, there is no need to use unique names for your callbacks (as in the traditional syntax).

Regarding plugins, add_action() or add_filter() are called in the __construct() of the plugin class.

Official docs: “Fires after WordPress has finished loading but before any headers are sent”.

add_action( 'init', array( $this, 'my_callback' ) );

Commonly used functions in the callback:

Official docs: “Fires as an admin screen or script is being initialized”.

add_action( 'admin_init', array( $this, 'my_callback' ) );

Commonly used functions in the callback:

Official docs: “Fires before the administration menu loads in the admin”.

add_action( 'admin_menu', array( $this, 'my_callback' ) );

Commonly used functions in the callback:

Official docs: “Fires when scripts and styles are enqueued”.

add_action( 'wp_enqueue_scripts', array( $this, 'my_callback' ) );

Commonly used functions in the callback:

Official docs: “Enqueue scripts and styles for the login page”.

add_action( 'login_enqueue_scripts', array( $this, 'my_callback' ) );

Commonly used functions in the callback:

Official docs: “Prints scripts or data in the head tag on the front end”.

add_action( 'wp_head', array( $this, 'my_callback' ) );

Commonly used functions in the callback:

Usually, the callback returns code for CSS, Javascript, meta tags, etc to be included in the head section (e.g. Google Adsense code).

Official docs: “Triggered after the opening body tag”.

add_action( 'wp_body_open', array( $this, 'my_callback' ) );

Commonly used functions in the callback:

Usually, the callback returns Javascript code to be included just after the opening body tag (e.g. Google Tag Manager code or Facebook SDK for JavaScript, etc).

Official docs: “Prints scripts or data before the closing body tag on the front end”.

add_action( 'wp_footer', array( $this, 'my_callback' ) );

Commonly used functions in the callback:

Usually, the callback returns Javascript code to be included just before the closing body tag.

Official docs: “Fires after the theme is loaded”.

add_action( 'after_setup_theme', array( $this, 'my_callback' ) );

Commonly used functions in the callback:

Official docs: “This hook is fired once WP, all plugins, and the theme are fully loaded and instantiated”.

add_action( 'wp_loaded', array( $this, 'my_callback' ) );

Commonly used functions in the callback:

Official docs: “Filters the post content”.

add_filter( 'the_content', array( $this, 'my_callback' ) );

Commonly used functions in the callback:

Any PHP code to manipulate the post content.

Official docs: “Fires when preparing to serve a REST API request”.

add_action( 'rest_api_init', array( $this, 'my_callback' ) );

Commonly used functions in the callback:

This content was originally published here.