WordPress.org

Ready to get started?Download WordPress

Forums

Store Locator Plus
Possible to load scripts only on pages with locator? (3 posts)

  1. gluethje
    Member
    Posted 1 year ago #

    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.

    http://wordpress.org/extend/plugins/store-locator-le/

  2. gluethje
    Member
    Posted 1 year ago #

    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.

  3. Charleston Software Associates
    Member
    Plugin Author

    Posted 1 year ago #

    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.

    See
    http://www.charlestonsw.com/slp-maps-and-late-loading-scripts/

    and

    http://www.charlestonsw.com/passing-php-variables-to-javascript/

    and

    http://www.charlestonsw.com/support/documentation/store-locator-plus/release-notes/

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.