Title: _load_script_textdomain_from_src
Published: May 20, 2026

---

# _load_script_textdomain_from_src( string $handle, string $src, string $domain, string $path, bool $is_module ): string|false

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/_load_script_textdomain_from_src/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/functions/_load_script_textdomain_from_src/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/_load_script_textdomain_from_src/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/_load_script_textdomain_from_src/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/functions/_load_script_textdomain_from_src/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/functions/_load_script_textdomain_from_src/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/_load_script_textdomain_from_src/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/functions/_load_script_textdomain_from_src/?output_format=md#wp--skip-link--target)

This function’s access is marked private. This means it is not intended for use 
by plugin or theme developers, only by core. It is listed here for completeness.

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

## 󠀁[Description](https://developer.wordpress.org/reference/functions/_load_script_textdomain_from_src/?output_format=md#description)󠁿

This is a shared implementation used by [load_script_textdomain()](https://developer.wordpress.org/reference/functions/load_script_textdomain/)
and [load_script_module_textdomain()](https://developer.wordpress.org/reference/functions/load_script_module_textdomain/)
to avoid duplicating the path resolution and file lookup logic.

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

 `$handle`stringrequired

Name of the script or script module identifier to register a translation domain 
to.

`$src`stringrequired

Absolute source URL of the script or script module.

`$domain`stringrequired

Text domain.

`$path`stringrequired

The full file path to the directory containing translation files, or an empty string
to use the default path from the text domain registry.

`$is_module`boolrequired

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

## 󠀁[Return](https://developer.wordpress.org/reference/functions/_load_script_textdomain_from_src/?output_format=md#return)󠁿

 string|false The JSON-encoded translated strings on success, false otherwise.

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

    ```php
    function _load_script_textdomain_from_src( string $handle, string $src, string $domain, string $path, bool $is_module ) {
    	/** @var WP_Textdomain_Registry $wp_textdomain_registry */
    	global $wp_textdomain_registry;

    	$locale = determine_locale();

    	if ( ! $path ) {
    		$path = $wp_textdomain_registry->get( $domain, $locale );
    	}

    	if ( $path ) {
    		$path = untrailingslashit( $path );
    	}

    	// If a path was given and the handle file exists simply return it.
    	$file_base       = 'default' === $domain ? $locale : $domain . '-' . $locale;
    	$handle_filename = $file_base . '-' . $handle . '.json';

    	if ( $path ) {
    		$translations = load_script_translations( $path . '/' . $handle_filename, $handle, $domain );

    		if ( $translations ) {
    			return $translations;
    		}
    	}

    	$relative       = false;
    	$languages_path = WP_LANG_DIR;

    	$src_url = wp_parse_url( $src );
    	if ( ! $src_url ) {
    		return load_script_translations( false, $handle, $domain );
    	}
    	$src_url['path'] ??= '';

    	$content_url = wp_parse_url( content_url() );
    	if ( ! $content_url ) {
    		return load_script_translations( false, $handle, $domain );
    	}

    	$plugins_url = wp_parse_url( plugins_url() );
    	$site_url    = wp_parse_url( site_url() );
    	$theme_root  = get_theme_root();

    	// If the host is the same or it's a relative URL.
    	if (
    		( ! isset( $content_url['path'] ) || str_starts_with( $src_url['path'], $content_url['path'] ) ) &&
    		( ! isset( $src_url['host'] ) || ! isset( $content_url['host'] ) || $src_url['host'] === $content_url['host'] )
    	) {
    		// Make the src relative the specific plugin or theme.
    		if ( isset( $content_url['path'] ) ) {
    			$relative = substr( $src_url['path'], strlen( $content_url['path'] ) );
    		} else {
    			$relative = $src_url['path'];
    		}
    		$relative = trim( $relative, '/' );
    		$relative = explode( '/', $relative );

    		/*
    		 * Ensure correct languages path when using a custom `WP_PLUGIN_DIR` / `WP_PLUGIN_URL` configuration,
    		 * a custom theme root, and/or using Multisite with subdirectories.
    		 * See https://core.trac.wordpress.org/ticket/60891 and https://core.trac.wordpress.org/ticket/62016.
    		 */

    		$theme_dir = array_slice( explode( '/', $theme_root ), -1 );
    		$dirname   = $theme_dir[0] === $relative[0] ? 'themes' : 'plugins';

    		$languages_path = WP_LANG_DIR . '/' . $dirname;

    		$relative = array_slice( $relative, 2 ); // Remove plugins/<plugin name> or themes/<theme name>.
    		$relative = implode( '/', $relative );
    	} elseif (
    		( ! isset( $plugins_url['path'] ) || str_starts_with( $src_url['path'], $plugins_url['path'] ) ) &&
    		( ! isset( $src_url['host'] ) || ! isset( $plugins_url['host'] ) || $src_url['host'] === $plugins_url['host'] )
    	) {
    		// Make the src relative the specific plugin.
    		if ( isset( $plugins_url['path'] ) ) {
    			$relative = substr( $src_url['path'], strlen( $plugins_url['path'] ) );
    		} else {
    			$relative = $src_url['path'];
    		}
    		$relative = trim( $relative, '/' );
    		$relative = explode( '/', $relative );

    		$languages_path = WP_LANG_DIR . '/plugins';

    		$relative = array_slice( $relative, 1 ); // Remove <plugin name>.
    		$relative = implode( '/', $relative );
    	} elseif ( ! isset( $src_url['host'] ) || ! isset( $site_url['host'] ) || $src_url['host'] === $site_url['host'] ) {
    		if ( ! isset( $site_url['path'] ) ) {
    			$relative = trim( $src_url['path'], '/' );
    		} elseif ( str_starts_with( $src_url['path'], trailingslashit( $site_url['path'] ) ) ) {
    			// Make the src relative to the WP root.
    			$relative = substr( $src_url['path'], strlen( $site_url['path'] ) );
    			$relative = trim( $relative, '/' );
    		}
    	}

    	/**
    	 * Filters the relative path of scripts used for finding translation files.
    	 *
    	 * @since 5.0.2
    	 * @since 7.0.0 The `$is_module` parameter was added.
    	 *
    	 * @param string|false $relative  The relative path of the script. False if it could not be determined.
    	 * @param string       $src       The full source URL of the script.
    	 * @param bool         $is_module Whether the source belongs to a script module (true) or a classic script (false).
    	 */
    	$relative = apply_filters( 'load_script_textdomain_relative_path', $relative, $src, $is_module );

    	// If the source is not from WP.
    	if ( ! is_string( $relative ) ) {
    		return load_script_translations( false, $handle, $domain );
    	}

    	// Translations are always based on the unminified filename.
    	if ( str_ends_with( $relative, '.min.js' ) ) {
    		$relative = substr( $relative, 0, -7 ) . '.js';
    	}

    	$md5_filename = $file_base . '-' . md5( $relative ) . '.json';

    	if ( $path ) {
    		$translations = load_script_translations( $path . '/' . $md5_filename, $handle, $domain );

    		if ( $translations ) {
    			return $translations;
    		}
    	}

    	$translations = load_script_translations( $languages_path . '/' . $md5_filename, $handle, $domain );

    	if ( $translations ) {
    		return $translations;
    	}

    	return load_script_translations( false, $handle, $domain );
    }
    ```

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

## 󠀁[Hooks](https://developer.wordpress.org/reference/functions/_load_script_textdomain_from_src/?output_format=md#hooks)󠁿

 [apply_filters( ‘load_script_textdomain_relative_path’, string|false $relative, string $src, bool $is_module )](https://developer.wordpress.org/reference/hooks/load_script_textdomain_relative_path/)

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

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

| Uses | Description | 
| [WP_Textdomain_Registry::get()](https://developer.wordpress.org/reference/classes/wp_textdomain_registry/get/)`wp-includes/class-wp-textdomain-registry.php` |

Returns the languages directory path for a specific domain and locale.

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

Loads the translation data for the given script handle and text domain.

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

Determines the current locale desired for the request.

  | 
| [wp_parse_url()](https://developer.wordpress.org/reference/functions/wp_parse_url/)`wp-includes/http.php` |

A wrapper for PHP’s parse_url() function that handles consistency in the return values across PHP versions.

  | 
| [get_theme_root()](https://developer.wordpress.org/reference/functions/get_theme_root/)`wp-includes/theme.php` |

Retrieves path to themes directory.

  | 
| [untrailingslashit()](https://developer.wordpress.org/reference/functions/untrailingslashit/)`wp-includes/formatting.php` |

Removes trailing forward slashes and backslashes if they exist.

  | 
| [content_url()](https://developer.wordpress.org/reference/functions/content_url/)`wp-includes/link-template.php` |

Retrieves the URL to the content directory.

  | 
| [plugins_url()](https://developer.wordpress.org/reference/functions/plugins_url/)`wp-includes/link-template.php` |

Retrieves a URL within the plugins or mu-plugins directory.

  | 
| [site_url()](https://developer.wordpress.org/reference/functions/site_url/)`wp-includes/link-template.php` |

Retrieves the URL for the current site where WordPress application files (e.g. wp-blog-header.php or the wp-admin/ folder) are accessible.

  | 
| [trailingslashit()](https://developer.wordpress.org/reference/functions/trailingslashit/)`wp-includes/formatting.php` |

Appends a trailing slash.

  | 
| [apply_filters()](https://developer.wordpress.org/reference/functions/apply_filters/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to a filter hook.

  |

[Show 6 more](https://developer.wordpress.org/reference/functions/_load_script_textdomain_from_src/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/_load_script_textdomain_from_src/?output_format=md#)

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

Loads the translation data for a given script module ID and text domain.

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

Loads the script translated strings.

  |

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

| Version | Description | 
| [7.0.0](https://developer.wordpress.org/reference/since/7.0.0/) | Introduced. |

## User Contributed Notes

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