Title: load_script_textdomain_relative_path
Published: January 14, 2019
Last modified: August 20, 2026

---

# apply_filters( ‘load_script_textdomain_relative_path’, string|false $relative, string $src, bool $is_module )

## In this article

 * [Parameters](https://developer.wordpress.org/reference/hooks/load_script_textdomain_relative_path/?output_format=md#parameters)
 * [Source](https://developer.wordpress.org/reference/hooks/load_script_textdomain_relative_path/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/hooks/load_script_textdomain_relative_path/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/hooks/load_script_textdomain_relative_path/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/hooks/load_script_textdomain_relative_path/?output_format=md#user-contributed-notes)

Filters the relative path of scripts used for finding translation files.

## 󠀁[Parameters](https://developer.wordpress.org/reference/hooks/load_script_textdomain_relative_path/?output_format=md#parameters)󠁿

 `$relative`string|false

The relative path of the script. False if it could not be determined.

`$src`string

The full source URL of the script.

`$is_module`bool

Whether the source belongs to a script module (true) or a classic script (false).

## 󠀁[Source](https://developer.wordpress.org/reference/hooks/load_script_textdomain_relative_path/?output_format=md#source)󠁿

    ```php
    $relative = apply_filters( 'load_script_textdomain_relative_path', $relative, $src, $is_module );
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/l10n.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/l10n.php#L1316)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/l10n.php#L1316-L1316)

## 󠀁[Related](https://developer.wordpress.org/reference/hooks/load_script_textdomain_relative_path/?output_format=md#related)󠁿

| Used by | Description | 
| [_load_script_textdomain_from_src()](https://developer.wordpress.org/reference/functions/_load_script_textdomain_from_src/)`wp-includes/l10n.php` |

Resolves and loads the translation JSON file for a given script or script module source URL.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/hooks/load_script_textdomain_relative_path/?output_format=md#changelog)󠁿

| Version | Description | 
| [7.0.0](https://developer.wordpress.org/reference/since/7.0.0/) | The `$is_module` parameter was added. | 
| [5.0.2](https://developer.wordpress.org/reference/since/5.0.2/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/hooks/load_script_textdomain_relative_path/?output_format=md#user-contributed-notes)󠁿

 1.   [Skip to note 2 content](https://developer.wordpress.org/reference/hooks/load_script_textdomain_relative_path/?output_format=md#comment-content-7594)
 2.    [Rodrigo Vieira Eufrasio da Silva](https://profiles.wordpress.org/rodrigomct/)
     [  3 months ago  ](https://developer.wordpress.org/reference/hooks/load_script_textdomain_relative_path/#comment-7594)
 3.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fload_script_textdomain_relative_path%2F%23comment-7594)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fload_script_textdomain_relative_path%2F%23comment-7594)
 4.  This filter exists to solve one specific problem: script translations silently
     breaking when the script’s src is served from a different host than your WordPress
     install — most commonly a CDN subdomain (e.g. [https://cdn.example.com/my-plugin/build/index.js](https://cdn.example.com/my-plugin/build/index.js)
     instead of [https://example.com/wp-content/plugins/my-plugin/build/index.js](https://example.com/wp-content/plugins/my-plugin/build/index.js)).
 5.  Looking at `_load_script_textdomain_from_src()` (which fires this filter), `$relative`
     is computed by comparing the script’s host/path against `content_url()`, `plugins_url()`,
     and `site_url()` in turn. If none of those hosts match — which happens whenever
     assets are proxied or served from a CDN with its own domain — $relative is left
     as false, and translations for that script silently fail to load (no error, the
     script just renders untranslated).
 6.  This filter runs right before that failure would happen, letting you supply the
     correct relative path yourself:
 7.      ```php
         add_filter( 'load_script_textdomain_relative_path', function ( $relative, $src, $is_module ) {
             // Only handle scripts actually served from our CDN.
             if ( ! str_starts_with( $src, 'https://cdn.example.com/my-plugin/' ) ) {
                 return $relative;
             }
     
             // Rebuild the relative path as if it were served from the plugin's
             // real location (relative to WP_LANG_DIR/plugins/my-plugin/).
             return str_replace( 'https://cdn.example.com/my-plugin/', '', $src );
         }, 10, 3 );
         ```
     
 8.  A few things worth knowing:
      – `$relative` must end up being a string for translations
     to load at all — returning false (or anything non-string) means “give up”, which
     is also useful if you want to explicitly disable translation lookup for specific
     external scripts instead of triggering warnings. – The `$is_module` parameter (
     added in WP 7.0) lets you apply different rewriting logic for script modules (
     registered via `wp_register_script_module()`) vs classic scripts, since both share
     this same resolution function. – The final filename is built as `md5($relative)
     + '.json'` — so `$relative` doesn’t need to be a real filesystem path, it just
     needs to be a STABLE, predictable string that you use consistently when naming
     your .json translation files (via `wp i18n make-json`).
 9.   [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fload_script_textdomain_relative_path%2F%3Freplytocom%3D7594%23feedback-editor-7594)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fload_script_textdomain_relative_path%2F)
before being able to contribute a note or feedback.