How can I have the listing address format different in each language?

First of all, here’s an arti­cle that explains to you how to dis­play the ele­ments that you need on the address part.

This arti­cle will explain how to have this struc­ture dif­fer­ent depend­ing on dif­fer­ent lan­guages. For exam­ple, let’s con­tin­ue the exam­ple from the oth­er side. Let’s say that for default we’ll dis­play the city, the coun­try and the street (in this order), for the French lan­guage we’ll dis­play the coun­try first, the city and the street and for Deutsch, we’ll have the city, the street and, final­ly, the coun­try. In this case, this is the code that we’ll use for default:

<span class="address__city" itemprop="addressLocality">{geolocation_city}</span>
<span class="address__country-short" itemprop="addressCountry">{geolocation_country_short}</span>
<span class="address__street">{geolocation_street}</span>

This is the code for French:

<span class="address__country-short" itemprop="addressCountry">{geolocation_country_short}</span>
<span class="address__city" itemprop="addressLocality">{geolocation_city}</span>
<span class="address__street">{geolocation_street}</span>

And for the Deutsch part:

<span class="address__city" itemprop="addressLocality">{geolocation_city}</span>
<span class="address__street">{geolocation_street}</span>
<span class="address__country-short" itemprop="addressCountry">{geolocation_country_short}</span>

The wrap­per part is the same one (as pre­sent­ed in the oth­er arti­cle) but there are two new ele­ments for the two addi­tion­al lan­guages:

function my_custom_listing_address ( $formats ) {
$formats = array(
'default' => '',
‘fr_FR’ => ‘’,
‘de_DE’ => ‘’) ;
return $formats;
}
add_filter( 'listable_localisation_address_formats', 'my_custom_listing_address', 15 ) ;

Now, the final step is to put all those parts in just one place, like this:

function my_custom_listing_address($formats) {
$formats = array(
'default' => '<span class="address__city" itemprop="addressLocality">{geolocation_city}</span>
<span class="address__country-short" itemprop="addressCountry">{geolocation_country_short}</span>
<span class="address__street">{geolocation_street}</span>’,
‘fr_FR’ => ‘<span class="address__country-short" itemprop="addressCountry">{geolocation_country_short}</span>
<span class="address__city" itemprop="addressLocality">{geolocation_city}</span>
<span class="address__street">{geolocation_street}</span>’,
‘de_DE’ => ‘<span class="address__city" itemprop="addressLocality">{geolocation_city}</span>
<span class="address__street">{geolocation_street}</span>
<span class="address__country-short" itemprop="addressCountry">{geolocation_country_short}</span>’);
return $formats;
}
add_filter('listable_localisation_address_formats', 'my_custom_listing_address', 15);

You can find the locale for all the lan­guages right here, on the WP_Locale col­umn. We had a look here when we took the de_DE and fr_FR parts for our lan­guages.

This should be all. Just give it a try and let us know if there any­thing comes up.

Updated on May 31, 2017

Was this article helpful?