php - Wordpress display name string manipulation -
i have set display name show both first name , last name using function below. how manipulate last name pull first letter of string? example, if sign john doe (first name= john, last name= doe), want display name john d.
thanks
function force_pretty_displaynames($user_login, $user) { $outcome = trim(get_user_meta($user->id, 'first_name', true) . " " . get_user_meta($user->id, 'last_name', true)); if (!empty($outcome) && ($user->data->display_name!=$outcome)) { wp_update_user( array ('id' => $user->id, 'display_name' => $outcome)); } } add_action('wp_login','force_pretty_displaynames',10,2);
this how solved using php's substr() function:
$outcome = trim( get_user_meta( $user->id, 'first_name', true ) . ' ' . substr( get_user_meta( $user->id, 'last_name', true ), 0, 1 ) . '.' );
above code pat j
full code display first name , initial of last name in wordpress below. if else wants use it, remember paste in theme's function.php file
function force_pretty_displaynames($user_login, $user) { $outcome = trim( get_user_meta( $user->id, 'first_name', true ) . ' ' . substr( get_user_meta( $user->id, 'last_name', true ), 0, 1 ) . '.' ); if (!empty($outcome) && ($user->data->display_name!=$outcome)) { wp_update_user( array ('id' => $user->id, 'display_name' => $outcome)); } } add_action('wp_login','force_pretty_displaynames',10,2);
Comments
Post a Comment