How to Change the Address Field Sublabels

Overview

Would you like to change the sublabels on the Address field in WPForms? The Address field has sublabels to let users know the type of information that should be added such as City, State etc. With a custom PHP code snippet you can easily change these sublabels and this tutorial will walk you through how to achieve this.

By default the Address form field will bring in additional fields. Each of those fields have their own labels called sublabels.

By default the Address form field will bring in additional fields.  Each of those fields have their own labels called sublabels.

Setup

The sublabels can be changed to display different text. This change can be applied specifically to the US address scheme, International address scheme or to both schemes by adding either or both of these code snippets to your site.

If you’re looking to translate Address sublabels, please see our documentation on How to Translate WPForms into a Different Language.

Change the sublabels for the US address scheme only

The below code snippet will allow you to change the sublabels on your Address field for the US scheme.

/**
 * Change the sublabels for the Address field for the US Address Scheme.
 *
 * @link https://wpforms.com/developers/how-to-change-the-address-field-sublabels/
 *
 */
function wpf_dev_address_field_properties( $properties, $field, $form_data ) {
  
  // check for address scheme
  if ( $field['scheme'] === 'us' ){
	  // Change sublabel values
	  $properties['inputs']['address1']['sublabel']['value'] = 'Street Address';
	  $properties['inputs']['address2']['sublabel']['value'] = 'Apartment #';
	  $properties['inputs']['city']['sublabel']['value'] = 'City';
	  $properties['inputs']['state']['sublabel']['value'] = 'State';
	  $properties['inputs']['postal']['sublabel']['value'] = 'Zip';
  	}
    return $properties;
}

add_filter( 'wpforms_field_properties_address' , 'wpf_dev_address_field_properties', 10, 3 );

Sublabels with the above code will now show different text

Change the sublabels for the International address scheme only

The below code snippet will allow you to change the sublabels on your Address field for the International scheme.

/**
 * Change the sublabels for the Address field for the International Address Scheme.
 *
 * @link https://wpforms.com/developers/how-to-change-the-address-field-sublabels/
 *
 */
function wpf_dev_address_field_properties( $properties, $field, $form_data ) {
  
  // check for address scheme
  if ( $field['scheme'] === 'international' ){
	  // Change sublabel values
	  $properties['inputs']['address1']['sublabel']['value'] = 'Address';
	  $properties['inputs']['address2']['sublabel']['value'] = 'Apartment / Suite #';
	  $properties['inputs']['city']['sublabel']['value'] = 'City';
	  $properties['inputs']['state']['sublabel']['value'] = 'State / Province / Region';
	  $properties['inputs']['postal']['sublabel']['value'] = 'Postal Code';
	  $properties['inputs']['country']['sublabel']['value'] = 'Country';
  	}
    return $properties;
}

add_filter( 'wpforms_field_properties_address' , 'wpf_dev_address_field_properties', 10, 3 );

And that’s it! Would you like to create additional address schemes to be used in your Address field? Take a look at our article on How to Create Additional Schemes for the Address Field.