Skip to content

Instantly share code, notes, and snippets.

@yuriinalivaiko
Last active October 6, 2022 18:46
Show Gist options
  • Save yuriinalivaiko/0cc8d895dfa37561d0c03ccdb7538d35 to your computer and use it in GitHub Desktop.
Save yuriinalivaiko/0cc8d895dfa37561d0c03ccdb7538d35 to your computer and use it in GitHub Desktop.
This code snippet displays the default value if the field value is empty in the profile view mode. You can add this code to the functions.php file in the active theme directory.
<?php
/**
* Display default value if the field value is empty in the profile view mode.
*
* @param string $value Field Value.
* @param string $default Field Default Value.
* @param string $key Field Key.
* @param string $type Field Type.
* @param array $data Field Data.
* @return string Field value to display.
*/
function um_field_value_show_default( $value, $default, $key, $type, $data ) {
if ( empty( $value ) && ! empty( UM()->fields()->viewing ) ) {
if ( ! empty( $default ) ) {
$value = $default;
}
}
return $value;
}
add_filter( 'um_field_value', 'um_field_value_show_default', 50, 5 );
@yuriinalivaiko
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment