Home>Support>Unable to deregister scripts!

Unable to deregister scripts!

Hi there,

I am trying to dequeue this script:

<script type="text/javascript" src="http://ffd-web.com/wp/wp-content/plugins/so-widgets-bundle/js/jquery.cycle.min.js?ver=1.7.1"></script>

Because I need to replace it with a specific tweaked version that won’t resize the slider on window.resize, unless the width delta is more than +-90px. I need this because I use to resize the Hero Widget according to window.height via a script, and I have to prevent a bad UX experience on mobile browsers due to the toggling browser address bar that always changes window.height, triggering window.resize events.

I’ve found the handlers in baseslider.class.php, and I’ve tried to dequeue them in this way, putting this code in function.php of my theme (based on _S):

function baseslider_fix() {
        // include needed to let is_plugin_active work on theme's function.php
	include_once( ABSPATH . 'wp-admin/includes/plugin.php' );

	if(is_plugin_active('so_widgets_bundle')) {
		//dequeue scripts
                wp_dequeue_script('sow-slider-slider');
		wp_deregister_script('sow-slider-slider');
		wp_dequeue_script('sow-slider-slider-cycle2');
		wp_deregister_script('sow-slider-slider-cycle2');

                //enqueue scripts
                wp_enqueue_etcetera.... (still have to write code)
	}
}
add_action( 'init', 'baseslider_fix', 100 );

However, it won’t work. I’ve tried other hooks, such as widget_init, after_theme_setup, wp_enqueue_scripts etc etc with priotity set up to 1000, tried to remove the if condition, removed the function wrapper, using wp_dequeue o wp_deregister alone, but nothing seems to trigger the script removal…

What should I change in my code? Where should I hook my action?

Thanks

This is our free support forum. Replies can take several days. If you need fast email support, please purchase a SiteOrigin Premium license.

  1. 7 years, 11 months ago Alex S
    Hi, I Work Here

    Hi Frafor,

    We don’t actually output the scripts until the_content. You should remove them after that point. Something like this will work:

    function baseslider_fix( $content ) {
    	// include needed to let is_plugin_active work on theme's function.php
    	include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
    
    	if( is_plugin_active( 'so-widgets-bundle/so-widgets-bundle.php' ) ) {
    		//dequeue scripts
    		wp_dequeue_script('sow-slider-slider');
    		wp_deregister_script('sow-slider-slider');
    		wp_dequeue_script('sow-slider-slider-cycle2');
    		wp_deregister_script('sow-slider-slider-cycle2');
    	}
    
    	return $content;
    }
    add_filter( 'the_content', 'baseslider_fix', 100 );
    
  2. 7 years, 11 months ago frafor

    Thanks alex, I will try later ;)

Replies on this thread are closed. Please create a new thread if you have a question, or purchase a SiteOrigin Premium license if you need one-on-one email support.

Get The Most Out of SiteOrigin with SiteOrigin Premium

Find Out More