Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rajucs/de35a25e6b41627a8c8bbf5c472a692a to your computer and use it in GitHub Desktop.
Save rajucs/de35a25e6b41627a8c8bbf5c472a692a to your computer and use it in GitHub Desktop.
Add radio button for user custom field in wordpress
add_action( 'show_user_profile', 'my_show_extra_profile_fields' );
add_action( 'edit_user_profile', 'my_show_extra_profile_fields' );
function my_show_extra_profile_fields( $user ) { ?>
<table>
<tr>
<?php
$gender = get_user_meta( $user->ID, 'gender', true );
?>
<th><label for="gender">gender</label></th>
<td>
<input type="radio" name="gender" id="gender" <?php checked( $gender, 'male' ); ?> value="male" >male
<input type="radio" name="gender" id="gender" <?php checked( $gender, 'female' ); ?>value="female">female<br>
<span class="description">Please enter your gender</span>
</td>
</tr>
</table>
<?php }
function my_save_extra_profile_fields( $user_id ) {
if ( !current_user_can( 'edit_user', $user_id ) )
return false;
update_usermeta( $user_id, 'gender', $_POST['gender'] );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment