Adding Extra Registration Fields

Adding extra registration fields with Theme My Login is extremely simple. It can be accomplished using the following three simple steps.

1. Add the new fields

First, copy /wp-content/plugins/theme-my-login/templates/register-form.php into your current theme's directory. Then, edit the newly copied template, adding the fields you wish to collect.

2. Validate the new fields (optional)

If you wish to require a field or perform any other kind of validation, you will do so using the registration_errors filter.

3. Save the new fields

You will save the new fields by creating a callback function for the user_register action. Within this callback function, you will more than likely be using update_user_meta() to save the fields, depending on your situation and what fields you are trying to save.


The following is an example of adding first name and last name to the registration form. These fields will be required.

Add the new fields

Add the following to your copy of register-form.php anywhere between the <form> and </form> tags.
	<label for="first_name<?php $template->the_instance(); ?>"><?php _e( 'First name', 'theme-my-login' ) ?></label>
	<input type="text" name="first_name" id="first_name<?php $template->the_instance(); ?>" class="input" value="<?php $template->the_posted_value( 'first_name' ); ?>" size="20" tabindex="20" />
	<label for="last_name<?php $template->the_instance(); ?>"><?php _e( 'Last name', 'theme-my-login' ) ?></label>
	<input type="text" name="last_name" id="last_name<?php $template->the_instance(); ?>" class="input" value="<?php $template->the_posted_value( 'last_name' ); ?>" size="20" tabindex="20" />

Validate the new fields

Add the following to theme-my-login-custom.php.
function tml_registration_errors( $errors ) {
	if ( empty( $_POST['first_name'] ) )
		$errors->add( 'empty_first_name', '<strong>ERROR</strong>: Please enter your first name.' );
	if ( empty( $_POST['last_name'] ) )
		$errors->add( 'empty_last_name', '<strong>ERROR</strong>: Please enter your last name.' );
	return $errors;
add_filter( 'registration_errors', 'tml_registration_errors' );

Save the new fields

Add the following to theme-my-login-custom.php.
function tml_user_register( $user_id ) {
	if ( !empty( $_POST['first_name'] ) )
		update_user_meta( $user_id, 'first_name', $_POST['first_name'] );
	if ( !empty( $_POST['last_name'] ) )
		update_user_meta( $user_id, 'last_name', $_POST['last_name'] );
add_action( 'user_register', 'tml_user_register' );