wpsl_address_shortcode_defaults

  1. Description
  2. Parameters
  3. Usage
  4. Changelog
  5. Source File
  6. Related

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:

AttributeDefaultValue
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.
nametrueTrue or false
addresstrueTrue or false
address2trueTrue or false
citytrueTrue or false
statetrueTrue or false
ziptrueTrue or false
countrytrueTrue or false
contact_detailsNot setTrue 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.
phonetrue when "Below the address on the landing page" is selected in "Location(s) of contact details", otherwise falseTrue or false
faxSame as phoneTrue or false
emailSame as phoneTrue or false
urlSame as phoneTrue or false
directionsfalseTrue or false. Shows a "Directions" link. With Google Maps it opens Google Maps, with the other map providers it opens OpenStreetMap.
clickable_contact_detailsThe "Make the contact details always clickable?" settingTrue or false. Turns the phone and fax into tel: links and the email into a mailto: link.
bold_contact_detailstrueTrue 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

VersionDescription
3.0Moved 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.13Added the directions and clickable_contact_details keys.
2.0Introduced.

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.