Changing the layout of addresses

The default display of addresses is in this format:

Address: Street Address
City
Region
ZIP or postcode
Country

That format is not always how addresses are set out in some countries, or you want to drop the region or country etc.

The following code, when added to functions.php of your child theme, or as a code snippet when you use the Code Snippets plugin, will output exactly the same as the default display above:

add_filter('geodir_show_post_address', 'geodir_change_address_order' , 100 , 2) ;
function geodir_change_address_order($html , $vars)
{
	global $post, $preview, $wpdb;
	$field_icon='';
	if (strpos($field_icon,'http') !== false) {$field_icon_af = '';}
		elseif($field_icon==''){$field_icon_af = '<i class="fa fa-home"></i>';}
		else{$field_icon_af = $field_icon; $field_icon='';}
	
	if(!$preview)
	{
		$html = '

';
		$html .= '<span class="geodir-i-location" style="'.$field_icon.'">'.$field_icon_af;
		$html .=  '&nbsp;Address:&nbsp;';
		$html .= '</span>';
		//print_r($_POST);
		
		if($post->post_address){ $html .= '<span itemprop="streetAddress">'.$post->post_address.'</span>
 ';}
		if($post->post_city){ $html .= '<span itemprop="addressLocality">'.$post->post_city.'</span>
 ';}
		if($post->post_region){ $html .= '<span itemprop="addressRegion">'.$post->post_region.'</span>
 ';}		
		if($post->post_zip){ $html .= '<span itemprop="postalCode">'.$post->post_zip.'</span>
 ';}
		if($post->post_country){ $html .= '<span itemprop="addressCountry">'.$post->post_country.'</span>
';}
		$html .= '

';
	}
	return $html ;
}

Always back up your functions.php before making changes, in case you make a mistake!

By adjusting parts of the code, we can move things around, or delete parts. Let’s for example change the format to:

Address:
Street Address
City ZIP or postcode
Country

The following changes to the above code give an example of how the address format can be customized:

		if($post->post_address){ $html .= '
<span itemprop="streetAddress">'.$post->post_address.'</span>
 ';}
		if($post->post_city){ $html .= '<span itemprop="addressLocality">'.$post->post_city.'</span> ';}
		if($post->post_zip){ $html .= '<span itemprop="postalCode">'.$post->post_zip.'</span>
 ';}
		if($post->post_country){ $html .= '<span itemprop="addressCountry">'.$post->post_country.'</span>
';}
		if($post->post_region){}