Enqueue Script in custom plugin before other

admin2025-01-08  3

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?

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?

Share Improve this question asked Oct 15, 2019 at 19:22 murcodermurcoder 991 gold badge1 silver badge13 bronze badges 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
Add a comment  | 

1 Answer 1

Reset to default 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);

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736270079a1401.html

最新回复(0)