WordPress Dequeue Script not working (with jquery)

I am trying to dequeue the following plugin scripts:

function afg_enqueue_cbox_scripts() {
wp_enqueue_script('jquery');
wp_enqueue_script('afg_colorbox_script', BASE_URL . "/colorbox/jquery.colorbox-min.js" , array('jquery'));
wp_enqueue_script('afg_colorbox_js', BASE_URL . "/colorbox/mycolorbox.js" , array('jquery'));
}

I tried adding this in functions.php:

Read More
add_filter('wp_print_styles', 'remove_mycred', 100);    
function remove_mycred() {
wp_dequeue_script( 'afg_colorbox_script' );
wp_dequeue_script( 'afg_colorbox_js' );
}

But it does not work at all – both scripts are still there.
There are other scripts that I have no problems dequeuing – just not those.

I suspect jquery has something to do with my problems?

thanks!

Blaise

Related posts

Leave a Reply

1 comment

  1. You have two problems here, you should use wp_enqueue_scripts hook to hook your function to. Secondly, you will need to go and look at the priority which the author used to enqueue these scripts, and then give your action hook a lower (higher number) priority. Your code should look something like this

    function remove_mycred() {
      wp_deregister_script( 'afg_colorbox_script' );
      wp_dequeue_script( 'afg_colorbox_script' );
      wp_deregister_script( 'afg_colorbox_js' );
      wp_dequeue_script( 'afg_colorbox_js' );
    }
    
    add_action( 'wp_enqueue_scripts', remove_mycred, 9999 );