WordPress

WordPress Hooks: Actions and filters

What are the hooks?

Hooks in WordPress essentially allow you to change or add code without editing core files. They are used extensively throughout WordPress and WooCommerce and are very useful for developers.
There are two types of hook: actions and filters.
  • Action Hooks allow you to insert custom code at various points (wherever the hook is run).
  • Filter Hooks allow you to manipulate and return a variable which it passes (for instance a product price).
Simply you can use this hooks in functions.php.

Like:

add_action( 'your_action_name', 'your_function_name_here' );

function your_function_name_here() {
// Your code 
} 

Filter Hooks.
add_filter( 'your_filter_name', 'your_function_name_here' );

function your_function_name_here( $your_variable ) {
// Your code
return $your_variable; // you need to return variable in case of filetr hooks
}

Comments

Popular posts from this blog

Ishwar chandra vidyasagar

WordPress All-In-One For Dummies

Wordpress Post Vs Page