Back to Top

How to Add Additional Profile Fields in WordPress

How to add custom fields to Registration & profile in WordPress

Sometimes you want to add extra fields into the default registration provided by WordPress.As we know, By default WordPress provide registration with some two-three fixed fields and for some reason we need to add some new fields into registration so, Today I am going to explain to you how you can add extra fields into registration and profile page in WordPress.

For adding extra fields, we need to create hook using an add_action function and you just need to place code into function.php file of theme and drag below PHP code.

Below action register_extra_fields is used to add an extra field into the layout of registration.

Here, I have just used the title, first name and last name as extra fields.

NOTE: Above code will be added after the existing fields in registration form but if you want to move it to top, you can change position of below code into wp-login.php file.

Next, we need to call action for checking errors and required fields which are like below

function check_fields_errors($login, $email, $errors) {
	global $firstname, $lastname;
	if ($_POST['first_name'] == '') {
		$errors->add('empty_realname', 'Error: Please enter First name');
	} else {
		$firstname = $_POST['first_name'];
	if ($_POST['last_name'] == '') {
		$errors->add('empty_realname', 'Error: Please enter Last name');
	} else {	
		$firstname = $_POST['last_name'];

Now,Let’s go ahead and create an action to add extra fields information into database.WordPress provides easiest way to add additional user information through the add_user_meta(), delete_user_meta(), get_user_meta(), update_user_meta() functions.This functions does not update the wp_users table, but update the wp_usermeta table. This is by default database layout provided by wordpress which allows one specific table to hold all additional user information.

add_action('user_register', 'register_post_fields');
function register_post_fields($user_id, $password='', $meta=array())  {
    $userdata = array();
    $userdata['ID'] = $user_id;
    $userdata['first_name'] = $_POST['first_name'];
    $userdata['last_name'] = $_POST['last_name'];
    $userdata['user_sal'] = $_POST['user_sal'];
    update_usermeta( $user_id, 'first_name', $_POST['first_name'] );
    update_usermeta( $user_id, 'last_name', $_POST['last_name'] );
    update_usermeta( $user_id, 'user_sal', $_POST['user_sal'] );	

That’s it we are done with adding extra fields on the registration form / registration page. Now let’s move to profile page.

First of all, we need to add action for displaying fields into profile page and then for updating information into database

Now, same like registration let’s update profile information into database using below action hooks:

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 ) { 
	global $current_user,$wpdb;
	if ( !current_user_can( 'edit_user', $user_id ) )
		return false;
	if (in_array('administrator', $current_user->roles) || $current_user->data->ID==$user_id){
					$userdata = array();
					$userdata['ID'] = $user_id;					
					$userdata['user_sal'] = $_POST['user_sal'];
					update_usermeta( $user_id, 'user_sal', $_POST['user_sal'] );


That’s all you are done with adding custom fields into registration and profile in WordPress

Thanks for reading and feel free to share your thoughts! Don’t Forget to Follow us on Twitter or Subscribe us to Get the Latest Updates.

Comments (8)

  1. thanks 🙂

  2. Thanks for sharing your thoughts on Profile.

  3. Thanks alot for this script.!

  4. Yes , now finally i got a full tutorial on this , thanks !

  5. Great information with many thanks. I have been searching for this all along and it was all here! Now I shall comfortably customize my word-press website with the fields of my choice.

    Is it possible to add anew menu for new users? I need a menu that is not visible to users that are not logged in

    1. Yeah you can create menu for logged in users only.

  6. HI Bhumi,

    I am new to wordpress and was looking for adding fields to Registration page and like your simple approach.
    When i copy paste your code in the theme Function.php file and after that i cannot load the wordpress dashboard or site.
    Do you think something is missing in the above code or i am putting it at wrong place.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Most Popular Posts

How to access Remote File using PHP

Posted on 7 years ago


How to use EXISTS and NOT EXISTS in MySQL?

Posted on 4 years ago