The example above shows that the hook is created to connect the mytheme_enqueue_script function with the wp_enqueue_scripts action. This hook triggers a new action on your site, therefore, it is called an action hook.

Hooks are often used in making plugin components of an application. It is not only used in content management systems (CMS) like WordPress but is also commonly used in e-commerce and intranet sites within an enterprise.

Furthermore, as we mentioned above, hooks are divided into two categories: action and filter. Action hook is used to add a process, while filter hook functions to change or modify the value of a process.

How to Use WordPress Hooks?

Using hooks in WordPress does require a bit of knowledge about HTML and PHP. However, even if you are a complete beginner, creating both action and filter hooks might not be as difficult as you think.

You only need to go to your post page, then switch to the text editor. When you are there, you can paste the hooks that you have copied from other sites or created yourself.

Creating an Action Hook

To add an action hook, you must activate the add_action () function in the WordPress plugin. This function can be activated by writing the patterns below in your functions.php file :

As we see above, hooks use priority scale to function properly. This scale is an automatic ordinal value based on a scale from 1 to 999. It defines the order precedence for functions associated with that particular hook.

A lower value of priority means that the function will be run earlier, while the higher one will be run later. The scale will show the output sequence of the functions installed when using the same target_hooks.

The default value of priority_scale is 10. You can arrange the scale according to the number of your target_hooks.

The array () function above sets your thumbnail to be displayed in 240 x 400 pixels. You should find the best size that fits your page perfectly.

after_password_reset

This action hook is activated when a user resets their password. The hook consists of two parameters; $user and $new_pass.

The hook should look like this:

do_action( 'after_password_reset', $user, $new_pass );

customize_loaded_components

This hook acts as a filter to exclude some WordPress components from its core process. Those are the functions that work on core files, such as wp-activate.php, wp-config-sample.php, or wp-settings.php. While the component is a collection of features on WordPress that represents one particular function in the widget.

However, it is important to note that customize_loaded_components cannot be added in a theme since it is only activated during ‘plugins loaded’ phase.

The hook consists of two parameters: $components and $this. It should be written like this:

The Author

Arief is a passionate digital content writer for Hostinger International and full-time SEO enthusiast. He enjoys writing as much as listening to Ed Sheeran old albums and EPs. Follow him on Twitter @agoomilar to find out his latest lame jokes and puns.