I am trying to get rid of a plugin's .js file in the but it's not working.

It's being called here {partial code):

class awqsf{

  const post_type = 'awqsf';

  function __construct(){       
    // style for front end
    add_action( 'wp_enqueue_scripts', array($this,'awsqf_front_styles'), false, '1.0', 'all',1 );           

  function awsqf_front_styles(){
    wp_register_script( 'awqsf-frontjs', plugins_url( 'js/awqsf-front.js', __FILE__ ), array('jquery'), '1.0' );

} //end class

I have tried a lot of different versions, wp_deregister_script and remove_action, but can't seem to get rid of it:

//deregister awqsf
function my_deregister_scripts() {
  //wp_register_script( 'awqsf-frontjs', plugins_url( 'js/awqsf-front.js', __FILE__ ), array('jquery'), '1.0' ); // the original wp_register_script
  wp_deregister_script( 'awqsf-frontjs', 'http://www.spijkerbroek.me/wp-content/plugins/advance-wp-query-search-filter/js/awqsf-front.js', array('jquery'), '1.0' );
  wp_deregister_script("wp_enqueue_scripts", 'http://www.spijkerbroek.me/wp-content/plugins/advance-wp-query-search-filter/js/awqsf-front.js', array("awqsf","awsqf_front_styles"), false, '1.0', 'all',1 );    
  wp_deregister_script( 'awqsf-frontjs', array('http://www.spijkerbroek.me/wp-content/plugins/advance-wp-query-search-filter/js/awqsf-front.js', 'jquery'), false, '1.0', 'all',1 );
  //function awsqf_front_styles(){} // the function
  //add_action( 'wp_enqueue_scripts', array($this,'awsqf_front_styles'), false, '1.0', 'all',1 );   // the original add_action
  remove_action( 'wp_enqueue_scripts', array('http://www.spijkerbroek.me/wp-content/plugins/advance-wp-query-search-filter/js/awqsf-front.js','awsqf_front_styles'), false, '1.0', 'all',1 );
  remove_action( 'awqsf', array('http://www.spijkerbroek.me/wp-content/plugins/advance-wp-query-search-filter/js/awqsf-front.js','awsqf_front_styles'), false, '1.0', 'all',1 );
  remove_action( 'awqsf', array('http://www.spijkerbroek.me/wp-content/plugins/advance-wp-query-search-filter/js/awqsf-front.js','wp_enqueue_scripts'), false, '1.0', 'all',1 );
add_action( 'wp_awqsf_scripts', 'my_deregister_scripts', 1 );

Can somebody get me into the right direction?

1 Answer 1


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() {

That's all.

  • 1
    You also use wp_dequeue_script. The OP was using (trying to use) wp_deregister_script.
    – s_ha_dum
    Oct 2, 2013 at 23:04
  • This is because the plugin registers the script and immediately after enqueue it. If I wp_deregister_script I'll get an error because WP try to enqueue a non-registered script. So if deregistering is mandatory it must be done after the dequeuing. But I think that the scope is remove the script from page and dequeing is enough for that. @s_ha_dum
    – gmazzap
    Oct 2, 2013 at 23:15
  • 1
    Yep, I get it. Just pointing out a difference in the approaches that might otherwise be missed.
    – s_ha_dum
    Oct 2, 2013 at 23:23
  • Sure. First line of answer is there for that, but maybe is not very highlighted. But now I'm lazy to edit answer, upvoted both your comments hoping it's an effective highlight :) @s_ha_dum
    – gmazzap
    Oct 2, 2013 at 23:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.