1. Home
  2. Snippets
  3. Change Sublabels (First, Middle, Last) for Name Field

Change Sublabels (First, Middle, Last) for Name Field

Heads up!

This article contains PHP code and is intended for developers. We offer this code as a courtesy, but don't provide support for code customizations or 3rd party development.

Dismiss

In WPForms, the Name field can be displayed in three formats:

  • Simple (displays a single field, so no sublabels)
  • First Last
  • First Middle Last

Select format for Name field in WPForms

When showing more than one subfield, sublabels will be displayed to show the user what they should enter for each.

Name field in WPForms with sublabels

The code below can be used to modify the default First, Middle, and Last subfield labels. Just replace the text between each set of single quotes with the new text you’d like to display.

/**
 * Customize name field properties.
 *
 * @param array $properties
 * @param array $field
 * @param array $form_data
 * @return array
 */
function wpf_dev_name_field_properties( $properties, $field, $form_data ) {
	
	// Change sublabel values
	$properties['inputs']['first']['sublabel']['value'] = 'First';
	$properties['inputs']['middle']['sublabel']['value'] = 'Middle';
	$properties['inputs']['last']['sublabel']['value'] = 'Last';

	return $properties;
}
add_filter( 'wpforms_field_properties_name' , 'wpf_dev_name_field_properties', 10, 3 );
Updated on November 20, 2017

Was this article helpful?