Unable to understand add_filter() for custom hook
-
I am unable to understand how add_filter() is processed by WordPress . I was playing around with custom hooks and found that add_filter(‘filter_tag’ , $var ) has to be before apply_filter(‘filter_tag , ‘callback’) while using a custom filter . So a code like below doesnt work :
function callback($var){ return ($var.'append'); } $var = 'testing'; echo $var; $var1 = apply_filters('custom_filter', $var); add_filter('custom_filter' , 'callback'); echo $var1;
Instead it needs to be :
add_filter('custom_filter' , 'callback'); $var1 = apply_filters('custom_filter', $var);
What I am facing a hard time understanding is when we hook into another plugin which has filter hooks how is my
add_filter('custom_filter' , 'callback');
executed before the plugin’sapply_filters('custom_filter', $var);
? WordPress most be executing code from different plugins sequentially .When different plugins are being executed aren’t their any chances of WordPress encountering aapply_filters('custom_filter', $var);
without the correspondingapply_filters('custom_filter', $var);
?Hope my question makes sense .
- The topic ‘Unable to understand add_filter() for custom hook’ is closed to new replies.