Very stubborn wp_register_script / add_action vs remove

What you need is simple dequeue the script. (I said dequeue and not deregister once the script is immediately enqueued and simply deregister it will throw an error, because WP will try to enqueue a non registered script).

But to dequeue something is necessary that something is first enqueued, so normally you have to look at the priority on which the enqueue function is called on 'wp_enqueue_scripts' and use a lower priority (higher priority number).

In your case, look at this line:

add_action('wp_enqueue_scripts', array($this,'awsqf_front_styles'),false,'1.0','all',1);

this is wrong. Plugin author is using the parameters for wp_enqueue_script in the function add_action.

If you look in Codex add_action accept 4 arguments:

add_action($tag, $function_to_add, $priority, $accepted_args)

So plugin author are using false as $priority and '1.0' as $accepted_args. 'all' and 1 will be ignored at all.

Off course this is an error, but WordPress can do its work despite it, using the default priority that is 10.

Once you know this, you can just use a lower priority (higher priority number) and dequeue the script:

add_action( 'wp_enqueue_scripts', 'remove_awsqf_front_script', 30);

function remove_awsqf_front_script() {
  wp_dequeue_script('awqsf-frontjs');
}

That’s all.

Leave a Comment