Enqueue Script in custom plugin before other

If the plugin does not include a priority, then the priority is “10” (the default).

So without changing (editing) the offending plugin, you can use a priority higher than 10 to load after, or lower than 10 to load earlier.

You mentioned that you want yours to load earlier. If that’s the case, the priority in your example is backwards. Setting foreign-plugin to 1 means it will load before my-plugin (set to 2). Instead, it should be:

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

Then “<MY-PLUGIN>” will load earlier than “<FOREIGN-PLUGIN>“. But as I mentioned, if it’s already in another plugin, you shouldn’t edit that and the default prior, so your enqueue should simply be:

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

(Or some priority number from 1-9). Then “my-plugin” will enqueue first.