Monday to Friday
10am to 6pm
Call us now on 02380 000567
 

Snippet to make Gravity Forms Address Entry more British

UK Union Jack

Gravity Forms is fantastic tool for collecting names, email address and postal addresses. However, GravityForms is a US plugin, so the default form labels are all US or Canada-centric. Here’s a simple tweak that you can add to functions.php to make your custom address form show UK-labels for addresses.

By default, Gravity Forms will show:

  • State / Province / Region
  • Zip / Postal Code

Which is fine, but for UK-only websites, we’d like to be a little more British. So if you copy the following snippet of code into your template functions.php, you’ll end up with much more UK-centric labels for your address entry on your Gravity Forms.

/**
 * Function to make the address fields GravityForms more British.
 */
function customiseFormLabels($addressTypes, $formID)
{
	$addressTypes['international']['zip_label'] 	= 'Post Code';
	$addressTypes['international']['state_label'] 	= 'County';	

	return $addressTypes;
}

// Use this one to change all gravity address forms to be more British
add_filter('gform_address_types', 'customiseFormLabels', 10, 2);

// To only change the labels for Form ID = 2, use the following instead.
// Note that the form ID goes after gform_address_types as gform_address_types_ID
//add_filter('gform_address_types_2', 'customiseFormLabels', 10, 2);

Instead, you’ll get the following:

  • County
  • Post Code

Much more British. You may now sing the National Anthem. :)

Written by Dan Harrison

Dan Harrison is the lead developer and director of WP Doctors Ltd, a web development agency specialising in writing bespoke tools for WordPress-based websites that save time, hassle and money.

2 Comments

Leave a comment
  1. David Lockie January 16, 2012 at 12:56 pm #

    Nice tip Dan :) Thanks for sharing.

    • Dan Harrison January 16, 2012 at 1:18 pm #

      Thanks David. A client asked me to sort it out recently, and I thought others would like to know too. :)

      Dan

Leave a Reply