wpml_exclude_post_from_auto_translate
- 类型
- filter
- 类别
- 杂项
- WPML 版本
- 4.6.7
说明
启用自动翻译所有内容后,WPML 会在文章创建或更新时立即自动对其进行翻译。
如果您需要排除特定文章以免被 TEA 翻译,您可以使用按 ID 排除文章的过滤器来实现。
重要提示:
WPML 会在 save_post 动作上触发翻译。请务必尽早添加此过滤器——在 save_post 动作运行之前。
另请注意,此钩子仅在自动翻译所有内容已在运行时才有效;它在首次启动 TEA 时不应用。
参数
add_filter( 'wpml_exclude_post_from_auto_translate', callable $function_to_add, 10, 2 );
回调函数参数
回调函数接受两个参数:
- $exclude (bool)设置为 true 以将文章从翻译中排除,或设置为 false 以允许翻译。
- $postId (int)正在翻译的文章 ID。
使用示例
示例
add_filter(
'wpml_exclude_post_from_auto_translate',
function ( $exclude, $postId ) : bool {
$postIdsToExclude = [ 10, 11, 12 ]; // Post IDs to exclude from Translate Everything.
return in_array( $postId, $postIdsToExclude, true );
},
10,
2
);
相关钩子
icl_ls_languages, wpml_sync_custom_field_copied_value, wpml_ls_enable_ajax_navigation, wpml_element_type, wpml_setting, wpml_sub_setting, wpml_forms_config_ninja-forms, wpml_forms_config_wpforms, wpml_tf_feedback_open_link, wpml_translatable_user_meta_fields