0

I've got a conflict with another plugin which is blocking the JS in my custom plugin with the hook:

add_action('wp_enqueue_scripts', '<FOREIGN-PLUGIN>');

Is there a way to enqueue my JS before all other plugins?

I tried already to set priority like

add_action('wp_enqueue_scripts', '<FOREIGN-PLUGIN>', 1);
add_action('wp_enqueue_scripts', '<MY-PLUGIN>', 2);

but it doesn't work. Any ideas?

2
  • Have you tried remove_action() to remove the other plugin's action, add yours, then add back the other plugin's action?
    – Sally CJ
    Commented Oct 16, 2019 at 2:07
  • your plugin should be independent of other plugin actions. that will avoid a lot of headaches in future development and customization. But if you insist on doing so, try wp_deregister_script( 'script-handle' ) then enqueue your script, other script. To register script: wp_register_script(....parameters....) and to enqueue script : wp_enqueue_script('script-handle')
    – maverick
    Commented Oct 16, 2019 at 6:48

1 Answer 1

0

Use dependencies. Dependencies are scripts that your script relies upon to be loaded first. The <FOREIGN-PLUGIN> in the example should be the handle that script was enqueued with.

$deps = array('<FOREIGN-PLUGIN>');
wp_enqueue_script( $handle, $src, $deps);

1
  • Not sure why someone downvoted this, as it's the correct answer and the correct way to enqueue scripts or CSS that are reliant upon other scripts/CSS
    – Mat
    Commented Mar 17, 2023 at 18:34

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.