GeoDirectory Documentation (DO NOT REMOVE)

Understanding hooks, actions and filters

Introduction

Your website pages are the result of WordPress and GD (and your theme and other plugins) checking your server files and your database to create the code that renders the page in your browser.

Actions and Filters are functions that can be modified to change the default functionality of GD and WordPress.

Actions or Filters are “hooked” into your pages by “hooking” them to action or filter hooks provided.

Action Hooks

Action hooks are special points in the WordPress or GD code that enable you to insert additional code and therefore customize the code to do some additional function.

For example, if you want to add a favicon to all your pages, you could hook into the wp_head action hook, a hook provided to add extra coding between your  <head> and </head> tags of your web pages. You would add the following code to your functions.php file:

[php]
function myplugin_favicon_head_code() {
echo ‘<link rel="icon" type="image/png" href="/images/favicon.ico">’;
}
add_action(‘wp_head’, ‘myplugin_favicon_head_code’);
[/php]

Actions make things happen.

Filter Hooks

Filter hooks are used to change the behavior of the default code.

For example, if you want to change the date format of the Events plugin, you can filter the default code to change the output. You would add the following code to your functions.php file:

[php]
function geodir_add_event_calendar_date_format_change($format){
return ‘d/m/Y’;
}
add_filter(‘geodir_add_event_calendar_date_format’, ‘geodir_add_event_calendar_date_format_change’,10,1);

[/php]

Filters change how things happen.

For a list of all Actions and Filters used by GeoDirectory, please refer to the GeoDIrectory Codex