Hiding ACFML “Field’s value in original language” block

“Field’s value in original language” block becomes annoying when you have long text in your field. We could not find any official documentation related to hiding this block. In order to make this block disappear we will check function which is responsible for displaying it. Additionally will do necessary adjustments. For this tutorial, we are using ACFML 1.4.0 version.

Explaining field_original_value function

Function, which is responsible for displaying original language block, called field_original_value. It is located in class-wpml-acf-field-annotations.php file under “classes” folder. Function snippet below:

private function field_original_value($field, $post_id) {
    if ( $this->is_secondary_language() ) {
        $custom_field_original_data = apply_filters('wpml_custom_field_original_data', null, $post_id, $field['_name'] );
	if ( isset( $custom_field_original_data['value'] ) && is_string( $custom_field_original_data['value'] ) ) {
	    echo "<div class='wpml_acf_original_value'>";
            echo "<strong>" . __("Field's value in original language", "acfml") . ":</strong><br>";
	    echo strip_tags( $custom_field_original_data['value'] );
	    echo "</div>";
	}
    }
}

As we can see from function above it uses $custom_field_original_data array for displaying information. If array “value” key ($custom_field_original_data[‘value’]) is not set, no text will be displayed. Additionally this function sets $custom_field_original_data array values by using wpml_custom_field_original_data filter.

Hiding “Field’s value in original language” block

In order to hide this block we must return array without “value” key. To do so we can add add_filter() function in our functions.php file. This function requires $tag and $function_to_add parameters. In addition for $tag parameter we will use ‘wpml_custom_field_original_data’ and for $function_to_add we will insert __return_empty_array() function name. Example below:

add_filter('wpml_custom_field_original_data', '__return_empty_array');

As a result each time function field_original_value will try to set $custom_field_original_data variable it will be an empty array. Additionally $custom_field_original_data variable will not pass if statement inside function. In other words, “Field’s value in original language” block will not be displayed.