Created
June 15, 2020 23:47
-
-
Save utkrishta/9fdd72e30e8ff2c73f8c38b5950f09e0 to your computer and use it in GitHub Desktop.
Remove WhiteSpace and ' ' at start and end from ACF fields
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Remove white space at start and end and remove 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('/ /', '', $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