Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if particular action or filter exists in a Wordpress theme

Tags:

php

wordpress

I want to check if any action/filter exists in the Wordpress theme.

I have tried has_action and has_filter. But the problem with these functions is that if the hook/filter exists and no callbacks are added to the hook or all callbacks are removed from the hook, these will return false.

like image 494
terriblecoder45 Avatar asked Oct 23 '25 17:10

terriblecoder45


1 Answers

There is not an built-in Wordpress function that will check for this. But you would be able to check if a filter exists using the following code:

// check for the existence of "the_content" filter
if( array_key_exists( 'the_content' , $GLOBALS['wp_filter']) ) {
}

The problem with this is that it will only check if the filter exists at the point at which the above code runs. So if the above code runs in a plugin, and a filter is added in a theme template file (which happens later in execution order, it won't show up yet.

like image 119
JakeParis Avatar answered Oct 26 '25 08:10

JakeParis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!