How to position user meta data field

I have 1 additional field I want to display on the user profile page (mainly admin users will use this)

I have done it but it is showing up at the very bottom of the page, I want it to sit in the area where the first name, last name and nickname are etc.

I tried different actions like personal_options_update as I believe that should position the box differently but then the field just vanishes.

add_action(‘show_user_profile’, ‘custom_user_profile_fields’);

add_action(‘edit_user_profile’, ‘custom_user_profile_fields’);

function custom_user_profile_fields( $user ) {
?>
<table class=”form-table”>
<tr>
<th>
<label for=”my_field”><?php _e( ‘My field’ ); ?></label>
</th>
<td>
<input type=”text” name=”my_field” id=”my_field” value=”<?php echo esc_attr( get_the_author_meta( ‘my_field’, $user->ID ) ); ?>” class=”regular-text” />
</td>
</tr>
</table>
<?php
}

add_action( ‘personal_options_update’, ‘update_extra_profile_fields’ );

add_action( ‘edit_user_profile_update’, ‘update_extra_profile_fields’ );

function update_extra_profile_fields( $user_id ) {
if ( current_user_can( ‘edit_user’, $user_id ) )
update_user_meta( $user_id, ‘my_field’, $_POST[‘my_field’] );
}

Read more here:: How to position user meta data field

Leave a Reply

Your email address will not be published. Required fields are marked *