我试图通过ICL_LANGUAGE_CODE我的插件获取当前的语言代码,但我不能,它没有定义,这是这个的结果
echo "Code: ".ICL_LANGUAGE_CODE;
Run Code Online (Sandbox Code Playgroud)
是
Code: ICL_LANGUAGE_NAME
Run Code Online (Sandbox Code Playgroud)
当我尝试以下操作时
global $sitepress;
$current_language = $sitepress->get_current_language();
echo "Code:". $current_language ;
Run Code Online (Sandbox Code Playgroud)
我得到空白屏幕。
我不知道通过什么方式可以得到它。
在主题functions.php 中一切正常。谢谢。
您可以使用 WPML 默认过滤器来获取当前语言,如下所示
$my_current_lang = apply_filters( 'wpml_current_language', NULL );
Run Code Online (Sandbox Code Playgroud)
结果将包含您当前的语言代码,例如: ar 、 en 、 fr ...等
小智 2
该常量已被弃用。请改用https://wpml.org/wpml-hook/wpml_current_language/
此处列出了全新的 WPML API,以防您有更多问题 https://wpml.org/documentation/support/wpml-coding-api/wpml-hooks-reference/
或者您可以随时在 wpml.org 官方论坛提问:)
| 归档时间: |
|
| 查看次数: |
21515 次 |
| 最近记录: |