Smart Way to Use Filters in wordpress

Today I’ll Going to Show You Have to Override a function using Filter hook

In this Example ,I wrote a simple function that append a simple text

function wpdadd_text($data){
return $data ;
}
 
add_filter('simple_text" ','wpdadd_text' ,10,3);
 
$values = apply_filters('simple_text','Welcome to WpDad');

Suppose we have Developed a plugin and we need to Give Developer Flixeable to Over above Code . Smartly we can  changed to.

function wpdadd_text($data){
return apply_filters('change_text' ,$data);
}
 
add_filter('simple_text','wpdadd_text' ,10,3);
$values = apply_filters('simple_text','Welcome to WpDad');

To override the above code without touching the code we Need to Apply   apply_filter Function

Support we need to Change “welcome to Wpdad” To “Thank you visiting Wpdad” at the We need to User Override_wpdadd filters

function wpdadd_text($data){
return apply_filters('change_text' ,$data);
}
add_filter('simple_text','wpdadd_text' ,10,3);
add_filter('change_text' ,'changed_text_call' ,99);
function changed_text_call($data){
$data ='Thank you visitng Wpdad';
return $data;
}
$values = apply_filters('simple_text','Welcome to WpDad');

Final Output will be “Thank You Visiting Wpdadd”;

Finally we have the Function as per Over Requirement

Add a Comment

Your email address will not be published. Required fields are marked *

thirteen − eight =