Viewing 7 replies - 1 through 7 (of 7 total)
  • Not easily. If you aren’t using the slider or totals the only JS that should load is the bit that clears the inut field, a whole two lines of it!

    If you really want to block the script when it’s not needed you can use conditional filters as expalined here: https://www.organizedthemes.com/loading-scripts-conditionally/

    Thread Starter CreativeFedora

    (@creativefedora)

    Thanks for the response. I had a similar question regarding Contact Form 7 that also loads JS and CSS files on each page be default. Based on CF7 documentation I implemented these snippets of code to only display the files on desired pages.

    Functions File

    add_filter( 'wpcf7_load_js', '__return_false' );
    add_filter( 'wpcf7_load_css', '__return_false' );

    Page Template

    <?php
        if ( function_exists( 'wpcf7_enqueue_scripts' ) ) {
            wpcf7_enqueue_scripts();
        }
    
        if ( function_exists( 'wpcf7_enqueue_styles' ) ) {
            wpcf7_enqueue_styles();
        }
    ?>

    Can I follow the same pattern as above for Quick PayPal Payments?

    That should work for paypal plugin.

    The function that loads the scripts and styles is called: qpp_enqueue_scripts

    So the two bits of code should be

    functions.php:

    add_filter( 'qpp_enqueue_scripts', '__return_false' );

    page.php (or single.php or whatever):

    <?php
        if ( function_exists( 'qpp_enqueue_scripts' ) ) {
            qpp_enqueue_scripts();
        }
    ?>

    I haven’t tested this so can you let me know if this works and I’ll add it to the plugin support site thing.

    Thread Starter CreativeFedora

    (@creativefedora)

    Negative. It didn’t work. I just added the code to the functions file to see if it removed the code and it did not after viewing the source code.

    OK,

    Try this: https://designloud.com/conditionally-load-plugins-in-wordpress/

    You need to dequeue the scripts then add the conditional statements.

    Thread Starter CreativeFedora

    (@creativefedora)

    Thanks. I was able to successfully implement and execute the programming to only load the desired files on the desired pages. I still need to finesse the implementation, but as a first draft it’s working.

    Excellent. closing this thread now as it seems to be all sorted now.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Only Load JS files on Button Pages’ is closed to new replies.