2572289473_f24c6561fc_z

What are wordpress Hooks

WordPress Hooks provide the ability to enhance, modify or customise a wordpress functionality by writing your own code without modifying the wordpress core code.

A WordPress Hook code can either be written directly in your themes (preferably child theme’s) functions.php or by creating your own plugin (recommended way)

Types of hooks

There are 2 types of wordpress hooks

  1. action hooks: These hooks can also be called as trigger hooks as they gets triggered based on a certain action/event. e.g. when a user registers on your site an action hook can be set up to geocode the user address and add the latitude longitude to the user_meta table.
  2. filter hooks: This hook allows to enhance or modify wordpress functionality or data e.g. it allows to use a custom template for certain post types, allows to use your custom page for lost password functionality, filter user data before displaying on browser or storing in the database.

Examples of hooks

user_register action hook: This action hook allows you to access data for a new user immediately after they are added to the database. The user id is passed to hook as an argument.

template_include filter hook: Allows to select custom template for your custom post types

 

Reference

List of action hooks

List of filter hooks

 

Creating Custom hooks for your own plugin

Creating your own custom hooks is also possible so that other developers can extend and modify it, without having to fork it.

Read more on how to create custom hooks

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *