Developers Guide

WP Travel Hooks: Actions and Filters

What are hooks?
In WordPress, hooks helps you to change or add code without editing core files of the plugin or theme. Hooks are very useful for those who want to customize the files.

Hook Types:

  • Actions hook allows you to insert custom code at the point where the hook is running.
  • Filters hook allows you to control, modify the variable and return it. ( For e.g trip duration ).

How can you use hooks?
You can use the hooks in different ways:

  • Child theme functions.php file.
  • Using third party plugins such as Code Snippets.

Action hooks example
do_action('your_action_name');”.

Here is where to place your code:

add_action( 'your_action_name', 'your_function_name' );
function your_function_name() {
// Your code goes here
}

Filter hooks example
apply_filter( 'your_filter_name', $args );”.

Here you can modify or control the argument and return it. ( You must return value ).

add_filter( 'your_filter_name', 'your_function_name' );
function your_function_name( $args ) {
// Your code
return $args;
}
  • Developers can use the Action hooks listed below to trigger the custom function in occurrence of certain event.
  • Filter hooks can be implemented if developers are willing to modify the functionality of existing functions.
  • Please make sure that no any customization work is being carried out in the main plugin file, since, all the code modifications will revert back with the update in the plugin file.
  • While making the changes in the codes using the given hooks, make sure your WP Travel version is up to date. While we are constantly working to add and enhance the functionality of the plugin, hooks might have been modified or deprecated. Using deprecated hooks will show no changes even if you are doing the correct work.

Powered by BetterDocs