WPML
add_action( 'wpml_language_has_switched', callable $function_to_add );
类型
action
WPML 版本
3.2.7

说明

  • 在 WordPress 查询中切换全局当前语言后,立即运行您的自定义函数。
  • 要更改当前语言,请使用 wpml_switch_language 钩子。

WPML 会将语言代码传递给您的回调。自 WPML 5.0 起,当调用者恢复语言切换时,也会运行此操作。在这种情况下,语言代码为 null。有关语言作用域如何打开和关闭的信息,请参见 wpml_switch_language

参数

$function_to_add
(callable) (必填) 应用过滤器时要运行的回调函数。

使用示例

示例
function my_plugin_actions() {
  // These actions will be executed right after the global current language has just changed. 
}

add_action( 'wpml_language_has_switched', 'my_plugin_actions' );

wpml_decode_custom_field, wpml_footer_language_selector, wpml_add_language_form_field, wpml_ls_exclude_in_menu, wpml_is_rtl, wpml_alternate_hreflang, wpml_head_langs, wpml_must_translate_canonical_url, wpml_browser_redirect_language_params, wpml_active_languages

所有 29 个 全站语言信息 钩子 →