Dynamic translation loading
Control when and how the Weglot JavaScript library is loaded
When dynamic translation is enabled, Weglot loads weglot.min.js from its CDN in wp_head and calls Weglot.initialize() immediately. These two filters let you change when that happens, or skip it altogether, to reduce the impact on page-load metrics.
Both only apply when weglot_translate_dynamics returns true. See Translations Hooks for the selectors and URL configuration that go with it.
Both filters are ignored when weglot_autoredirect_js returns true. In that mode the JavaScript library performs the browser-language redirect from the original-language page, so it can neither be skipped nor deferred without breaking the redirect.
weglot_load_dynamics_in_original_language
$load
bool
true
Return false to skip loading the library entirely while the visitor is on the original-language page. Translated pages are unaffected.
Use it when your dynamic content only needs translating on translated URLs — the original language does not need the library to display its own content.
<?php
add_filter( 'weglot_load_dynamics_in_original_language', '__return_false' );weglot_defer_dynamics_js
$defer
bool
false
Return true to load weglot.min.js with the defer attribute and move Weglot.initialize() into the script's load handler, so it no longer blocks rendering in wp_head.
<?php
add_filter( 'weglot_defer_dynamics_js', '__return_true' );This filter is opt-in on purpose. Deferring widens the window during which dynamic content can appear untranslated: the library starts parsing later, so content injected early by other scripts may be visible in the original language for a moment before being translated.
Enable it when you are optimising Core Web Vitals and can accept that trade-off; leave it off if a brief flash of untranslated dynamic content is not acceptable.
Using both
The two filters combine: skip the library in the original language, and defer it everywhere else.