> 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' );
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://developers.weglot.com/cms/wordpress/filters/dynamic-translation-loading.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
