An action can be removed in time that pass since it is added to it is fired. So after is added, before is fired.
You say the plugin has thiss code:
add_action('wp_enqueue_scripts', 'poll_scripts');
function poll_scripts() {
// code
}
But you don’t say if this code is inside a function hooked somewhere.
If it is not in any function, the action is added as soon the plugins is loaded, so you (so before theme is loaded) so if you do it from a theme, you can remove this action everywhere before wp_head()
, first hook you have available on theme is after_setup_theme
,
So this one will work:
add_action('template_redirect', 'remove_poll_scripts');
function remove_poll_scripts() {
if ( is_home() ) remove_action('wp_enqueue_scripts', 'poll_scripts');
}
if in your functions.php
you just write
remove_action('wp_enqueue_scripts', 'poll_scripts');
It will work because functions.php
is loaded after the plugin and before 'wp_enqueue_scripts'
is fired: so you are perfectly in time but you can’t check in which page remove the scripts.
Moreover, if you try to do the exactly same thing from a plugin, and in your plugin file you write
remove_action('wp_enqueue_scripts', 'poll_scripts');
without wrapping it in any hook, it can fail: no one can assure your plugin is not loaded before the plugin that add the script and in that case you try to remove the action before it is added.