@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?
@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?
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.
@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.
@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.