• Resolved bbrophy

    (@bbrophy)


    Hi, this plugin is installed on a site I’m working on. I’d like to stop the scripts from loading on certain pages (i.e., those without a plugin shortcode). I’ve tried this inside and outside my conditional, but with no luck:

    remove_action( ‘wp_enqueue_scripts’, array(‘google_business_reviews_rating’, ‘wp_js_load’) );

    This is based on the plugin’s index.php file. Not sure if anyone has any tips – thanks!

    The scripts are ultimately being delivered minified and combined via wp fastest cache – not sure if that matters.

    • This topic was modified 5 years, 10 months ago by bbrophy.
Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Noah Hearle

    (@designextreme)

    @bbrophy I’ll send something through shortly to cover this.

    A recommendation: why not use a caching/compression plugin to serve all scripts as one file – then it will load once per visit and save on the load time throughout the website?

    Plugin Author Noah Hearle

    (@designextreme)

    @bbrophy After a little look at the documentation and in forums, the unloading of this script is not possible with this method. The class is not referred to by name as you listed in your example.

    I may add something in the future to look for pages/posts containing the shortcode and then onload load the JavaScript and style sheet in these pages. It’s not as straight-forward as I would like.

    May I ask why you want to do this on your website? Is it because of load times or a conflict with the theme or another plugin?

    Thread Starter bbrophy

    (@bbrophy)

    I’m just going through and trying to optimize script and stylesheet loading across the site (e.g., code splitting, conditionally loading Contact Form 7 scripts). If it’s not possible, no worries. I thought that might be the case.

    Some people said that you can only remove_action on class object instances saved to a variable. Others said that you should be able to just to use the class name if it wasn’t saved to a variable, but that doesn’t seem to work. Anyway, cheers! Appreciate you taking the time.

    Plugin Author Noah Hearle

    (@designextreme)

    @bbrophy That’s ok, it’s always good to ask!

    With the site optimisation, if you can have all the theme and plugin scripts load in a compressed form as just one file, that’s the most effective way to reduce load time. If there are slightly different consolidated scripts across the website, you won’t be taking advantage of it already being cached by the browser (reducing the footprint to near-zero). It does depend upon the website to some degree.

    Also, this plugin’s script file is pretty small even uncompressed so having it load once per visit isn’t going to have a noticeable effect.

    One consideration, if reducing load time is vital: choose to hide the author avatars or set these to one local image.

    Plugin Author Noah Hearle

    (@designextreme)

    @bbrophy I have a solution for the style sheet. I’ll outline the rough idea…

    1. In the plugin, disable the style sheet;
    2. In your theme’s “functions.php” file (you may need to create this), load the same style sheet (/wp-content/plugins/g-business-reviews-rating/wp/css/css.css) with the conditions you require (e.g. is_page('reviews') or similar).

    Note that some functionality may be lost if the style sheet is disabled in the plugin (such as the SVG stars and their animation).

    I found something that will handle the code at Stack Exchange.

    I still don’t recommend loading the styles (or script) for just the page(s) where the short code exists.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Remove Plugin Action on Certain Pages’ is closed to new replies.