Skip to content

Instantly share code, notes, and snippets.

@utkrishta
Created June 15, 2020 23:47
Show Gist options
  • Save utkrishta/9fdd72e30e8ff2c73f8c38b5950f09e0 to your computer and use it in GitHub Desktop.
Save utkrishta/9fdd72e30e8ff2c73f8c38b5950f09e0 to your computer and use it in GitHub Desktop.
Remove WhiteSpace and ' ' at start and end from ACF fields
<?php
//Remove white space at start and end and remove &nbsp; from ACF fields
function my_acf_update_value( $value, $post_id, $field ) {
if( is_string($value) ) {
$value = rtrim($value);
$value = ltrim($value);
$value = preg_replace('/&nbsp;/', '', $value);
}
return $value;
}
add_filter('acf/update_value/type=wysiwyg', 'my_acf_update_value', 10, 3);
add_filter('acf/update_value/type=text', 'my_acf_update_value', 10, 3);
add_filter('acf/update_value/type=textarea', 'my_acf_update_value', 10, 3);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment