I'm creating a wordpress plugin that uses Select2. What is the correct way of checking if Select2 has been loaded already before registering the script?
If I don't check it the plugin will be loaded twice.
I'm creating a wordpress plugin that uses Select2. What is the correct way of checking if Select2 has been loaded already before registering the script?
If I don't check it the plugin will be loaded twice.
You can use wp_script_is, which determines if script has been registered, enqueued, etc.
if( ! wp_script_is( 'custom-script', 'enqueued' ) ) {
// the plugin is not enqueued
}
Update: wp_enqueue_script
will check if specific plugin is loaded and will not load it twice, so in most cases you don't have to worry about this. Well, it should works if you doing things the right way, e.g. use built-in functions for dealing with custom scripts, like wp_register_script
, etc.