pre_load_textdomain
云策文档标注
概述
pre_load_textdomain 是一个 WordPress 过滤器,用于控制是否跳过加载 .mo 文件。通过返回非 null 值,可以中断加载过程并返回该值。
关键要点
- 过滤器名称:pre_load_textdomain
- 作用:允许开发者拦截 .mo 文件的加载,用于优化或自定义翻译加载逻辑
- 参数:$loaded(bool|null,加载结果)、$domain(string,文本域)、$mofile(string,MO 文件路径)、$locale(string|null,区域设置)
- 返回值:返回非 null 值将跳过加载,直接返回该值
- 引入版本:WordPress 6.3.0
代码示例
add_filter('pre_load_textdomain', '__return_false', -42);注意事项
可用于优化场景,例如当站点仅使用英语(en_US)时,通过此过滤器阻止语言文件加载以提升性能。
原文内容
Filters whether to short-circuit loading .mo file.
Description
Returning a non-null value from the filter will effectively short-circuit the loading, returning the passed value instead.
Parameters
$loadedbool|null-
The result of loading a .mo file. Default null.
$domainstring-
Text domain. Unique identifier for retrieving translated strings.
$mofilestring-
Path to the MO file.
$localestring|null-
Locale.
Source
$loaded = apply_filters( 'pre_load_textdomain', null, $domain, $mofile, $locale );
Changelog
| Version | Description |
|---|---|
| 6.3.0 | Introduced. |
Skip to note 2 content
Fernando Tellado
Optimization if you don’t need languages added
In case you want to prevent languages from loading if your site will be only in English (en_US), stop this hook:
add_filter(‘pre_load_textdomain’, ‘__return_false’, -42);