> For the complete documentation index, see [llms.txt](https://developers.weglot.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developers.weglot.com/cms/wordpress/filters/dynamic-translation-loading.md).

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

{% hint style="info" %}
Both filters on this page are available since Weglot 6.3.
{% endhint %}

Both only apply when `weglot_translate_dynamics` returns `true`. See [Translations Hooks](/cms/wordpress/filters/translations-filters.md) for the selectors and URL configuration that go with it.

{% hint style="warning" %}
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.
{% endhint %}

#### 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
<?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
<?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.

```php
<?php

add_filter( 'weglot_translate_dynamics', '__return_true' );
add_filter( 'weglot_load_dynamics_in_original_language', '__return_false' );
add_filter( 'weglot_defer_dynamics_js', '__return_true' );
```
