Home/Tutorial/WordPress/Action Filter Hook in WordPress
Action Filter Hook in WordPress 2016-11-28T12:16:41+00:00

Action Filter Hook in WordPress

Hooks are shortcuts that allow you to “hang” your own code on the original functionality of WordPress or any theme or plugin. Hooks come in two forms, Filters and Actions.

1. Actions
2. Filters

 

Video Tutorial: 


Actions allow you to inject a custom function or bit of code into a specific place. Actions do stuff

add_action(‘layers_after_slider_widget_inner’, ‘my_slide_content’);

After finishing office time my work I used to buy Almonds for my wife, if I have money in my wallet and If I dont forget.
add_action( $hook, $function_to_add, $priority, $accepted_args );
add_action( $after_office_time, $purchase_almonds, 10, 2 );

 

 

Filters are a type of Hook allowing you to change or remove an existing function. Filters change stuff

apply_filters( ‘layers_read_more_text’, __( ‘Your Text’, ‘text_domain’ ) );

apply_filters( ‘wife_mon_kharap’, __( ‘Wifer mon valo’, ‘layerswp’ ) );

 

Frequently Asked Questions: 
The difference between add_filter and apply_filters?
In the most basic terms, apply_filters is used to initialize a filter hook. add_filter assigns a new function to hooks that have already been created.

Example:

To filter the widget title.

Sample 1: apply_filter
apply_filters( ‘layers_read_more_text’, __( ‘Your Text’, ‘text_domain’ );

Sample 2: add_filter

function custom_widget_title() {
$title = ‘Welcome’;
return $title;
}
add_filter(‘widget_title’, ‘custom_widget_title’);
Another example:

Here’s an example. WooCommerce has it’s own API and system of hooks and filters. One such hook is woocommerce_after_main_content. In the code of WooCommerce, the code apply_filters(‘woocommerce_after_main_content’…. is used.

A programmer of another plugin/theme developer ) would be able to hook into this by using

add_filter(‘woocommerce_after_main_content’,….

 

 

WordPress Theme Development For ThemeForest