Support » Plugin: Store Locator Plus for WordPress » [Plugin: Google Maps via Store Locator Plus] Possible to load scripts only on pages with locator?

  • Is there any way to only load all of the google maps scripts on pages that actually have the locator?

    There are something like 6 different scripts loading from google, which is less than ideal for performance. I understand these are necessary for the plugin to function, but I don’t want all these scripts loading on every single page of a website, when only one page actually uses them.

Viewing 2 replies - 1 through 2 (of 2 total)
  • I figured out how to do it myself, but of course plugin updates will probably break it.

    1. I created a new page template called store-locator-pages.php, and set that as the page template for the page where I am using the plugin
    2. I did a search of the plugin folder for a string in one of the the google maps api url that was being loaded and found that the scripts are all being loaded in this file: plugins/store-locator-le/include/storelocatorplus-actions_class.php
    3. the search showed that the scripts were being loaded in a function starting on line 218 of this file, starting with static function wp_enqueue_scripts() {
    4. at the top of this function, inside the first bracket I added an if statement: if( is_page_template( 'store-locator-pages.php' )){ and wrapped the entire function in this if statement

    It works! No map scripts except on pages using that template. Of course updates to the plugin will probably overwrite this, but in this case nothing bad will happen. It will just go back to loading the scripts on every page, and I can go back in and add the if statement again if I want to.

    In the meantime, here’s hoping the plugin authors will offer an option to only load the scripts on pages that actually use it.

    Plugin Author Store Locator Plus


    You can purchase the Pro Pack and turn off “force loading javascript”. As long as your themes & plugins behave then the scripts only load when needed.




Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Plugin: Google Maps via Store Locator Plus] Possible to load scripts only on pages with locator?’ is closed to new replies.