How you can add new extra fields(input text and textarea) in WordPress user profile page

Hi guys! In this tutorial I will explain to you how you can add new extra fields in Wordpress user profile page. You can add new extra fields for subscribers or Wordpress users.

So, if you want to add new input fields in Wordpress user profile page, you can use this code:

function add_new_field($new_field) {

/* Add new input field */
$new_field['idfield'] = __('Name of your field');

return $new_field;
}

add_filter('user_contactmethods', 'add_new_field');

To display this extra fields on your website, you must use this code:

echo get_user_meta($user_id->id,"idfield",true);

In this way you can add input text fields. If you want to add textarea, use this code:

add_action( 'show_user_profile', 'add_textarea' );
add_action( 'edit_user_profile', 'add_textarea' );

function add_textarea($user) {

?>

<textarea name="text"></textarea>

<?php

}

To insert data from textarea in your database use this code:

add_action( 'personal_options_update', 'save_text' );
add_action( 'edit_user_profile_update', 'save_text' );

function save_text( $user_id ) {

update_usermeta( $user_id, 'text', $_POST['text'] );

}









Leave a Comment