• Resolved josiahmann

    (@josiahmann)


    Awesome work on this plugin.

    Is there any way to change the front-end page templates without editing the actual plugin via hooks, filters, or something? I primarily just want to change the order of the html elements ( for example I want to move the search bar below the map) but don’t want to mess with the plugin itself.

    https://www.ads-software.com/plugins/wp-store-locator/

Viewing 4 replies - 1 through 4 (of 4 total)
  • I’d also be very interested in this. Ideally as a template override feature similar to how the WordPress Parent/Child theme override works. Modern Tribe’s The Event Calendar does a nice implementation of this by allowing you to place your template overrides in your theme.

    @josiahmann I’ve been evaluating various Store Locator plugins and this seems to be the best out there right now, so we’ll probably end up using it. If I find a nice way to do this, without hacking the plugin, I’ll post it here.

    @josiahmann,
    Figured it out… On line 319 of wp-store-locator.php @tijmensmit includes the apply_filters() function before returning the two template files for the plugin. This allows us to create a filter where we can override the plugin templates with custom templates.

    I’ve added this function to my theme to set the paths to the default and “store below” layouts to my overrides:

    // Add custom template overrides for the WP Store Locator Templates
    add_filter('wpsl_templates', 'foo_wpsl_templates');
    function foo_wpsl_templates($templates) {
    
    	$templates = array (
    		array (
    			'name' => __( 'Default', 'wpsl' ),
    			'path' => get_stylesheet_directory() . '/wp-store-locator/default.php'
    		),
    		array (
    			'name' => __( 'Show the store list below the map', 'wpsl' ),
    			'path' => get_stylesheet_directory() . '/wp-store-locator/store-listings-below.php'
    		)
    	);
    	return $templates;
    }
    Thread Starter josiahmann

    (@josiahmann)

    That is exactly what I was looking for! Thanks for your response Menslow.

    Plugin Author Tijmen Smit

    (@tijmensmit)

    Once I finished coding the 2.0 version I will definitely write proper documentation with code examples ??

    In the 2.0 version the $templates array will require an id to be present. So you will need to add it after you updated the plugin and save the settings page again to keep your custom template working.

    $templates = array(
            array(
                'id'   => 'default',
                'name' => __( 'Default', 'wpsl' ),
                'path' => WPSL_PLUGIN_DIR . 'frontend/templates/default.php'
            ),
            array(
                'id'   => 'below_map',
                'name' => __( 'Show the store list below the map', 'wpsl' ),
                'path' => WPSL_PLUGIN_DIR . 'frontend/templates/store-listings-below.php'
            )
        );
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Changes to Page Template’ is closed to new replies.