{"id":22640,"date":"2016-07-31T13:09:42","date_gmt":"2016-07-31T13:09:42","guid":{"rendered":"https:\/\/wpgeodirectory.com\/docs\/?p=22640"},"modified":"2017-04-05T23:44:36","modified_gmt":"2017-04-05T23:44:36","slug":"changing-the-layout-of-addresses","status":"publish","type":"post","link":"https:\/\/wpgeodirectory.com\/docs\/changing-the-layout-of-addresses\/","title":{"rendered":"Changing the layout of addresses"},"content":{"rendered":"<p>The default display of addresses is in this format:<\/p>\n<blockquote><p><i class=\"fa fa-home\"><\/i> Address: Street Address<br \/>\nCity<br \/>\nRegion<br \/>\nZIP or postcode<br \/>\nCountry<\/p><\/blockquote>\n<p>That format is not always how addresses are set out in some countries, or you want to drop the region or country etc.<\/p>\n<p>The following code, when added to <em><strong>functions.php<\/strong><\/em> of your child theme, or as a code snippet when you use the <a href=\"https:\/\/wpgeodirectory.com\/docs\/useful-plugins\/#snippets\">Code Snippets plugin<\/a>, will output exactly the same as the default display above:<\/p>\n<p>[php]<br \/>\nadd_filter(&#8216;geodir_show_post_address&#8217;, &#8216;geodir_change_address_order&#8217; , 100 , 2) ;<br \/>\nfunction geodir_change_address_order($html , $vars)<br \/>\n{<br \/>\n\tglobal $post, $preview, $wpdb;<br \/>\n\t$field_icon=&#8221;;<br \/>\n\tif (strpos($field_icon,&#8217;http&#8217;) !== false) {$field_icon_af = &#8221;;}<br \/>\n\t\telseif($field_icon==&#8221;){$field_icon_af = &#8216;&lt;i class=&quot;fa fa-home&quot;&gt;&lt;\/i&gt;&#8217;;}<br \/>\n\t\telse{$field_icon_af = $field_icon; $field_icon=&#8221;;}<\/p>\n<p>\tif(!$preview)<br \/>\n\t{<br \/>\n\t\t$html = &#8216;<\/p>\n<p>&#8216;;<br \/>\n\t\t$html .= &#8216;&lt;span class=&quot;geodir-i-location&quot; style=&quot;&#8217;.$field_icon.&#8217;&quot;&gt;&#8217;.$field_icon_af;<br \/>\n\t\t$html .=  &#8216;&amp;nbsp;Address:&amp;nbsp;&#8217;;<br \/>\n\t\t$html .= &#8216;&lt;\/span&gt;&#8217;;<br \/>\n\t\t\/\/print_r($_POST);<\/p>\n<p>\t\tif($post-&gt;post_address){ $html .= &#8216;&lt;span itemprop=&quot;streetAddress&quot;&gt;&#8217;.$post-&gt;post_address.'&lt;\/span&gt;<br \/>\n &#8216;;}<br \/>\n\t\tif($post-&gt;post_city){ $html .= &#8216;&lt;span itemprop=&quot;addressLocality&quot;&gt;&#8217;.$post-&gt;post_city.'&lt;\/span&gt;<br \/>\n &#8216;;}<br \/>\n\t\tif($post-&gt;post_region){ $html .= &#8216;&lt;span itemprop=&quot;addressRegion&quot;&gt;&#8217;.$post-&gt;post_region.'&lt;\/span&gt;<br \/>\n &#8216;;}<br \/>\n\t\tif($post-&gt;post_zip){ $html .= &#8216;&lt;span itemprop=&quot;postalCode&quot;&gt;&#8217;.$post-&gt;post_zip.'&lt;\/span&gt;<br \/>\n &#8216;;}<br \/>\n\t\tif($post-&gt;post_country){ $html .= &#8216;&lt;span itemprop=&quot;addressCountry&quot;&gt;&#8217;.$post-&gt;post_country.'&lt;\/span&gt;<br \/>\n&#8216;;}<br \/>\n\t\t$html .= &#8216;<\/p>\n<p>&#8216;;<br \/>\n\t}<br \/>\n\treturn $html ;<br \/>\n}<br \/>\n[\/php]<\/p>\n<p><i class=\"fa fa-exclamation-triangle fa-2x\" style=\"color: red;\"><\/i> <span style=\"color: #ff0000;\">Always back up your <em><strong>functions.php<\/strong><\/em> before making changes, in case you make a mistake!<\/span><\/p>\n<p>By adjusting parts of the code, we can move things around, or delete parts. Let&#8217;s for example change the format to:<\/p>\n<blockquote><p><i class=\"fa fa-home\"><\/i> Address:<br \/>\nStreet Address<br \/>\nCity ZIP or postcode<br \/>\nCountry<\/p><\/blockquote>\n<p>The following changes to the above code give an example of how the address format can be customized:<\/p>\n<p>[php]<br \/>\n\t\tif($post-&gt;post_address){ $html .= &#8216;<br \/>\n&lt;span itemprop=&quot;streetAddress&quot;&gt;&#8217;.$post-&gt;post_address.'&lt;\/span&gt;<br \/>\n &#8216;;}<br \/>\n\t\tif($post-&gt;post_city){ $html .= &#8216;&lt;span itemprop=&quot;addressLocality&quot;&gt;&#8217;.$post-&gt;post_city.'&lt;\/span&gt; &#8216;;}<br \/>\n\t\tif($post-&gt;post_zip){ $html .= &#8216;&lt;span itemprop=&quot;postalCode&quot;&gt;&#8217;.$post-&gt;post_zip.'&lt;\/span&gt;<br \/>\n &#8216;;}<br \/>\n\t\tif($post-&gt;post_country){ $html .= &#8216;&lt;span itemprop=&quot;addressCountry&quot;&gt;&#8217;.$post-&gt;post_country.'&lt;\/span&gt;<br \/>\n&#8216;;}<br \/>\n\t\tif($post-&gt;post_region){}<br \/>\n[\/php]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/wpgeodirectory.com\/docs\/changing-the-layout-of-addresses\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Changing the layout of addresses&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1676,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[15],"tags":[],"amp_validity":null,"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/wpgeodirectory.com\/docs\/wp-json\/wp\/v2\/posts\/22640"}],"collection":[{"href":"https:\/\/wpgeodirectory.com\/docs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wpgeodirectory.com\/docs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wpgeodirectory.com\/docs\/wp-json\/wp\/v2\/users\/1676"}],"replies":[{"embeddable":true,"href":"https:\/\/wpgeodirectory.com\/docs\/wp-json\/wp\/v2\/comments?post=22640"}],"version-history":[{"count":0,"href":"https:\/\/wpgeodirectory.com\/docs\/wp-json\/wp\/v2\/posts\/22640\/revisions"}],"wp:attachment":[{"href":"https:\/\/wpgeodirectory.com\/docs\/wp-json\/wp\/v2\/media?parent=22640"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wpgeodirectory.com\/docs\/wp-json\/wp\/v2\/categories?post=22640"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wpgeodirectory.com\/docs\/wp-json\/wp\/v2\/tags?post=22640"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}