Description
This filter allows you to change the default options for the address shortcode.
By default, the store name and all the address fields are shown on the store pages. The phone, fax, email and url are only shown when “Below the address on the landing page” is selected in Location(s) of contact details on Store Locator > Settings > User Experience. That option is only available when “Create landing pages?” is enabled on Store Locator > Settings > Local Pages. See the User Experience settings.
You can also set the attributes on a single shortcode, for example [wpsl_address id="123" directions="true"]. Attributes on the shortcode override the defaults from this filter.
Parameters
$shortcode_defaults - (array) The current defaults for the [wpsl_address] shortcode.
The available shortcode attributes:
| Attribute | Default | Value |
|---|---|---|
id | '' | The id of the store you want to show the address for. This is only required if you use this shortcode on a page that isn't a store location page. |
name | true | True or false |
address | true | True or false |
address2 | true | True or false |
city | true | True or false |
state | true | True or false |
zip | true | True or false |
country | true | True or false |
contact_details | Not set | True or false. Turns the phone, fax, email and url on or off together. A contact attribute that you set yourself, like phone="false", still wins. |
phone | true when "Below the address on the landing page" is selected in "Location(s) of contact details", otherwise false | True or false |
fax | Same as phone | True or false |
email | Same as phone | True or false |
url | Same as phone | True or false |
directions | false | True or false. Shows a "Directions" link. With Google Maps it opens Google Maps, with the other map providers it opens OpenStreetMap. |
clickable_contact_details | The "Make the contact details always clickable?" setting | True or false. Turns the phone and fax into tel: links and the email into a mailto: link. |
bold_contact_details | true | True or false. Shows the Phone, Fax, Email and Url labels in bold. |
The city, state and zip code are shown in the order of the "Address format" setting on the User Experience page.
Usage
This example will set the country to false, which will hide it from the shortcode output:
| add_filter( 'wpsl_address_shortcode_defaults', 'custom_address_shortcode_defaults' ); | |
| function custom_address_shortcode_defaults( $shortcode_defaults ) { | |
| $shortcode_defaults['country'] = false; | |
| return $shortcode_defaults; | |
| } |
This example shows the contact details and a directions link in every [wpsl_address] shortcode, whatever the “Location(s) of contact details” setting is:
| add_filter( 'wpsl_address_shortcode_defaults', 'custom_address_shortcode_defaults' ); | |
| function custom_address_shortcode_defaults( $shortcode_defaults ) { | |
| // Show the phone, fax, email and url, and a link to the directions. | |
| $shortcode_defaults['contact_details'] = true; | |
| $shortcode_defaults['directions'] = true; | |
| return $shortcode_defaults; | |
| } |
Only the contact details that are filled in for the store are shown.
Changelog
| Version | Description |
|---|---|
| 3.0 | Moved to includes/frontend/shortcodes/class-shortcodes.php. The phone, fax, email and url defaults now follow the "Location(s) of contact details" setting, instead of always true. Added the contact_details and bold_contact_details keys. |
| 2.2.13 | Added the directions and clickable_contact_details keys. |
| 2.0 | Introduced. |
Source File
This filter is located in /includes/frontend/shortcodes/class-shortcodes.php.
Placement
The code needs to be placed in the functions.php file inside your active theme folder.