UM Select2 i18n Fix
Loads Select2 (full) early, removes Select2 i18n bundles (incl. en.js), and injects an early AMD guard to prevent “reading 'define'” crashes.
by Rytis Petkevicius (rytisp@gmail.com) · github.com/rytisp/um-select2-i18n-fix
Install
No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:
wp plugin install https://github.com/rytisp/um-select2-i18n-fix/archive/refs/heads/main.zipWordPress Utltimate Member (UM) Select2 i18n Fix
Fixes the common TypeError: Cannot read properties of undefined (reading 'define') caused by Ultimate Member’s bundled Select2 i18n files (e.g. en.js) when loaded before the Select2 AMD loader.
This plugin:
- Loads the Select2 full build (
select2.full.min.js) early in the<head>so AMD is always defined. - Removes Select2 i18n bundles (like
en.jsand other locale files) that cause crashes. - Injects a JavaScript guard to prevent fatal errors if i18n executes before AMD is ready.
- Leaves Select2 working as expected in English (default) or your chosen language.
Why?
Ultimate Member (UM) includes its own copy of Select2. In some setups (especially with caching/optimization plugins like Autoptimize, WP Rocket, LiteSpeed), the i18n files load before the core Select2 script, resulting in:
This plugin fixes the load order and prevents the crash.
Installation
From GitHub
- Download um-select2-i18n-fix.zip.
- In WordPress Admin:
Plugins → Add New → Upload Plugin → Choose File→ upload the ZIP. - Click Activate.
Manual
- Upload the
um-select2-i18n-fixfolder into/wp-content/plugins/. - Go to WordPress Admin → Plugins.
- Activate UM Select2 i18n Fix.
Requirements
- WordPress 5.8+
- Ultimate Member 4.0.13 (or later, adjust path if UM changes structure)
How It Works
- Guard script in
<head>: Defines a stubS2.defineandS2.requireif missing, so i18n can’t crash the page. - Blocks i18n files: Removes UM’s
assets/libs/select2/i18n/*.jsfrom the scripts queue. - Forces core load: Ensures
select2.full.min.jsis loaded before anything else, in<head>.
Troubleshooting
- Still see the error?
- Clear all caches (page cache, object cache, CDN, optimizer).
- Hard refresh with
Ctrl+Shift+R(or Cmd+Shift+R). - Check console for
[UM Select2 Fix]log — it reports whether jQuery, Select2, and AMD are present.
- Optimization plugins
Exclude the following from aggregation/defer/async:
/wp-content/plugins/ultimate-member/assets/libs/select2/select2.full.min.js/wp-content/plugins/ultimate-member/assets/libs/select2/i18n/
- UM updates
If UM changes its internal file paths, update the plugin’s reference toselect2.full.min.js.
License
(C) 2025 All Rights Reserved
Contributing
Pull requests welcome. If UM changes its file structure in future updates, patches to update the Select2 path are appreciated.