Loading two versions of same JS libary

sweetalert.js uses the global swal in both version 1.*.* and version 2.*.* of its library. Therefore if you load both js/sweetalert.min.js and js/sweetalert-latest.min.js the first one to define the global swal will be used, the second will be ignored or cause a console error.

To prevent this only load one library such as:

// PHP
wp_enqueue_script( 'sweet-alert-latest', plugin_dir_url( __FILE__ ) . 'js/sweetalert-latest.min.js', array(), $this->version, false );

And update any references targeting old SweetAlert code according to the migration documentation


Alternatively If you want to use both libraries concurrently you could utilise ES6 modules with a compiler such as babel

// Javascript
import swal as oldswal from '/my-local-js-directory/sweetalert.1.5.1.js';
import swal as newswal from '/my-local-js-directory/sweetalert.2.1.0.js';

// Old alert
oldswal({
  // Old alert config here
});

// New alert
newswal({
  // New alert config here
});

Ref: Babel

With common JS you could do something like this

const oldswal = require('/my-local-js-directory/sweetalert.1.5.1.js')
const newswal = require('/my-local-js-directory/sweetalert.2.1.0.js')