Loading…

What are the difference between action hook and filter hook in WordPress?

1. Actions Hook

Actions Hook are triggered by particular events that take place in WordPress such as changing themes, publishing a post, or displaying an administration screen. It is a custom PHP function defined in your plugin and hooked, i.e., set to respond, to some of these events.

 

Actions offently do one or more of the following things

  • Modify database data
  • Send an email message
  • Modify the generated administration screen or front end page sent to a user web browser.

 

Here are some Actions Functions listed

  • has_action()
  • do_action()
  • add_action()
  • remove_action() etc
 
2. Filters Hook

Filters Hook are functions that WordPress passes data through, at certain points in execution, just before taking some action with the data. It sits between the database and the browser and between the browser and the database; all most all input and output in WordPress pass through at least one filter hook.

 

The necessary steps to add your filters to WordPress are listed:

  • Create the PHP function that filters the data
  • Hook to the screen in WordPress, by calling add_filter()
  • Put your PHP function in a plugin file and activate it.

 

Here are some Filters Functions listed

  • has_filter()
  • doing_filter()
  • add_filter()
  • remove_filter() etc

Suggest An Answer

No suggestions avaliable!

Latest post from Wordpress Interview Questions

Ask Question