WPML
wpml_exclude_post_from_auto_translate
Type
filter
Category
Miscellaneous
WPML Version
4.6.7

Description

When Translate Everything Automatically is enabled, WPML translates a post automatically as soon as it is created or updated.

If you need to exclude specific posts from being translated by TEA, you can do so by using a filter that excludes posts by their IDs.

Important:
WPML triggers translation on the save_post action. Make sure to add this filter as early as possible—before the save_post action runs.

Also note that this hook only works while Translate Everything Automatically is already running; it does not apply when starting TEA for the first time.

Arguments

add_filter( 'wpml_exclude_post_from_auto_translate', callable $function_to_add, 10, 2 );

Callback Function Parameters

The callback function accepts two parameters:


  • $exclude (bool)Set to true to exclude the post from translation, or false to allow translation.

  • $postId (int)The ID of the post being translated.

Example usage

Example

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

All 30 Miscellaneous hooks →