How to add Custom Field in WordPress Registration Form - Kvcodes
X

Congrats, You are Subscribed to Receive Updates.

How to add Custom Field in WordPress Registration Form


Adding Custom Field in WordPress Registration Form is a easy and simple to add it.  Just follow the below steps to add your custom fields in your WordPress registration Page. First we need to create the form fields  to ask extra details from user.  Now we are going to add Mobile number and get it from the user.  Lets create the Form by using the following code.

<?php 

function kv_user_registration_form() { ?>
    <p>
		<label for="mob_no">Mobile No:<br>
		<input type="text" name="mob_no" id="mob_no" class="input" value="" size="20"></label>
	</p>
<?php 
} 

add_action('register_form', 'kv_user_registration_form');

The above function will hook a custom form field to registration form.  and your registration form looks like this.

user-registration-form

Now we need to get the value of the ” mob_no” and store it on corresponding user table row with the help of following function.

function kv_save_registration_form_data($user_id) {
	$user = array();
	
	$user['ID'] = $user_id;
	$user['mobile_no'] = $_POST['mob_no'];	
	
	// Adding tyhe custom field to database
	$kvads= add_user_meta( $user_id, 'mobile_no', $user['mobile_no']);		
}
add_action('user_register', 'kv_save_registration_form_data', 10, 1 );

Now, just open your new user field mobile_no is available on your “wp_usermeta” table.  This is a very basic one to Add a custom filed, you can verify it before submitting the form to database.

That’s it to add Custom Field in WordPress Registration Form.

commenter

About Varadharaj V

The founder of Kvcodes, Varadharaj V is an ERP Analyst and a Web developer specializing in WordPress(WP), WP Theme development, WP Plugin development, Frontaccounting(FA), Sales, Purchases, Inventory, Ledgers, Payroll & HRM, CRM, FA Core Customization, OpenCart Theme Development, PHP, HTML, CSS, jQuery, Bootstrap development and content SEO.

Comment Below

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

*

Current ye@r *

Menu

Sidebar

Subscribe E-mail Updates

Congrats, You are Subscribed to Receive Updates.

Advertisement

Category Posts