wpsl_templates

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

Description

This filter allows you to add your own store locator template, loaded from outside the WP Store Locator plugin folder. That way you don’t lose your changes when you update the plugin.

How to create the template file is explained in Load a Custom Store Locator Template.

Adding a template with this filter doesn’t activate it. Go to Store Locator > Appearance, open the Themes tab, and click the toggle on the card of your template. To use the template on one page only, set it in the shortcode on that page: [wpsl template="my-custom-template"]. The template attribute always overrides the template selected on the Appearance page.

Parameters

$templates - (array) The list of templates. Each template is an array with these keys:

KeyRequiredDescription
idYesA unique ID. Don't use default, horizontal or vertical. You use the ID in the template shortcode attribute, and the outer #wpsl-wrap div gets a wpsl-{id}-template class.
nameYesThe name shown on the template card on the Appearance page.
pathYesThe full path to the template file. If the file doesn't exist, the Default template is used instead.
descNoThe description shown below the name on the template card. Defaults to "Custom template".
placeholderNoThe URL of the image shown on the template card. Defaults to a generic custom template image.
has_panelNoSet it to true for a copy of the Vertical template. The outer div then gets the wpsl-flex and wpsl-has-panel classes, the panel height from the Appearance settings is applied, and the styled dropdowns are always used. Without it, the panel layout isn't applied.
customize_pathNoSet on the built-in Default template. WP Store Locator 3.0.3 doesn't read it, so you can leave it out.
exclude_css_propertiesNoSet on the built-in Vertical template. WP Store Locator 3.0.3 doesn't read it, so you can leave it out.

Usage

This example loads a custom template from the wpsl-templates folder in your active theme folder:

function my_wpsl_custom_template( $templates ) {
$templates[] = [
'id' => 'my-custom-template',
'name' => 'My custom template',
'desc' => 'Shown under the template name on the Appearance page.',
'path' => get_stylesheet_directory() . '/wpsl-templates/custom.php',
// Only when you copied vertical.php:
// 'has_panel' => true,
];
return $templates;
}
add_filter( 'wpsl_templates', 'my_wpsl_custom_template' );

If your template is a copy of vertical.php, remove the // in front of the 'has_panel' => true line.

The styles for the Horizontal and Vertical templates only apply to the .wpsl-horizontal-template and .wpsl-vertical-template classes. A copy gets its own wpsl-{id}-template class instead, so add the original class back with the wpsl_template_outer_classes filter:

add_filter( 'wpsl_template_outer_classes', 'my_wpsl_template_classes' );
function my_wpsl_template_classes( $classes ) {
if ( in_array( 'wpsl-my-custom-template-template', $classes, true ) ) {
$classes[] = 'wpsl-vertical-template'; // or wpsl-horizontal-template
}
return $classes;
}

The default templates are located in /wp-content/plugins/wp-store-locator/includes/frontend/templates: default.php, horizontal.php and vertical.php.

Custom templates written for WP Store Locator 2 keep working. They are detected automatically and run in legacy mode, and their card on the Appearance page gets a warning icon. Read the same page to learn how to update the template to the v3 structure.

Changelog

VersionDescription
3.0Moved to includes/core/functions/functions-templates.php. Added the optional desc, placeholder and has_panel keys. Templates are now activated on the Appearance page, or with the template shortcode attribute, instead of the "Store Locator template" dropdown in the User Experience settings. The default templates moved to includes/frontend/templates, and the "below_map" template was replaced by Horizontal. Templates written for 2.x run in legacy mode.
2.0Added the required id key. Moved to inc/wpsl-functions.php.
1.2.20Introduced.

Source File

This filter is located in /includes/core/functions/functions-templates.php.

Placement

The code needs to be placed in the functions.php file inside your active theme folder.