To all would-be close-voters: This question is not a duplicate, because I need to remove all scripts added by plugin using
remove_action
.In Very stubborn wp_register_script / add_action vs remove used
wp_dequeue_script
function to remove scripts one by one, but I need to remove them all (which was added by plugin usingadd_action
) usingremove_action
!
wp_dequeue_script
function can't remove custom code like this:
add_action('wp_head', 'print_style');
function print_style() {
echo '<style>body { margin: 0; }</style>';
}
I have installed WP Polls plugin. I am using it in some of the pages and need to deregister its styles and scripts on other pages.
I found some code in the plugin which registers scripts:
Function: Enqueue Polls JavaScripts/CSS
add_action('wp_enqueue_scripts', 'poll_scripts');
function poll_scripts() {
// code
}
So for deregistering its scripts i am using next code in my functions.php:
add_action( 'wp_enqueue_scripts', 'deregister_polls_scripts_and_styles' );
function deregister_polls_scripts_and_styles() {
if ( is_home() ) {
remove_action( 'wp_enqueue_scripts', 'poll_scripts');
}
}
So it must deregister polls scripts on homepage, but id does not. What i am doing wrong?
P.S. 1
Scripts are removing in this case:
add_action( 'after_setup_theme', 'wc_deregister_polls_scripts_and_styles' );
function wc_deregister_polls_scripts_and_styles() {
remove_action('wp_enqueue_scripts', 'poll_scripts');
remove_action('wp_head', 'poll_head_scripts');
}
But i need to remove it on some pages like this:
add_action( 'after_setup_theme', 'wc_deregister_polls_scripts_and_styles' );
function wc_deregister_polls_scripts_and_styles() {
if ( is_page('developers') ) {
remove_action('wp_enqueue_scripts', 'poll_scripts');
remove_action('wp_head', 'poll_head_scripts');
}
}
So in this case it does not work.
I have installed another plugin and all works fine in this case. Same actions, BUT all works:
add_action( 'wp_enqueue_scripts', 'wc_deregister_scripts_and_styles' );
function wc_deregister_scripts_and_styles() {
if ( !is_home() && !is_tax('brand') ) {
remove_action( 'wp_enqueue_scripts', 'uag_frontend_styles', 999 );
remove_action( 'wp_footer', 'uag_footer_scripts');
}
}
P. S. 2
This is another plugin.
add_action('wp_enqueue_scripts', 'uag_frontend_styles', 999);
function uag_frontend_styles() {
/* main stylesheet */
wp_register_style( 'uag_style', uag_url . 'css/uag.css');
wp_enqueue_style('uag_style');
}
This is Polls:
add_action('wp_enqueue_scripts', 'poll_scripts');
function poll_scripts() {
global $text_direction;
if(@file_exists(get_stylesheet_directory().'/polls-css.css')) {
wp_enqueue_style('wp-polls', get_stylesheet_directory_uri().'/polls-css.css', false, '2.63', 'all');
} else {
wp_enqueue_style('wp-polls', plugins_url('wp-polls/polls-css.css'), false, '2.63', 'all');
}
if('rtl' == $text_direction) {
if(@file_exists(get_stylesheet_directory().'/polls-css-rtl.css')) {
wp_enqueue_style('wp-polls-rtl', get_stylesheet_directory_uri().'/polls-css-rtl.css', false, '2.63', 'all');
} else {
wp_enqueue_style('wp-polls-rtl', plugins_url('wp-polls/polls-css-rtl.css'), false, '2.63', 'all');
}
}
$poll_ajax_style = get_option('poll_ajax_style');
$pollbar = get_option('poll_bar');
wp_enqueue_script('wp-polls', plugins_url('wp-polls/polls-js.js'), array('jquery'), '2.63', true);
// Other same code
}
is_front_page()
instead ofis_home()
. If everything is fine with that, can you please share the code written in plugin to enqueue the js file.