For the complete documentation index, see llms.txt. This page is also available as Markdown.

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 filters on this page are available since Weglot 6.3.

Both only apply when weglot_translate_dynamics returns true. See Translations Hooks for the selectors and URL configuration that go with it.

weglot_load_dynamics_in_original_language

Argument
Type
Default

$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

Argument
Type
Default

$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.