AddToAny supports dynamic loading, e.g. image sharing, content loaded via Ajax, and similar publisher/developer use cases, so the required assets remain available by default.
Developers can conditionally disable the core AddToAny script, and dequeue the plugin’s CSS & JS, for example:
add_action( 'wp_enqueue_scripts', function() {
// Your conditional goes here. For example:
// Allow only on single posts (of any post type)
if ( is_singular() ) return;
// Remove AddToAny core script.
// Note: This disables AddToAny's ability to load dynamically.
add_filter( 'addtoany_script_disabled', '__return_true' );
// Remove AddToAny plugin's JS & CSS.
wp_dequeue_script( 'addtoany' );
wp_dequeue_style( 'addtoany' );
}, 21);
Thread Starter
Jonas
(@gnuworld)
Hi @micropat – thanks for getting back to me. It would be nice to have an option to disable it that doesn’t require a developer.
To me it would make sense that unticking the “show sharing buttons” checkbox for a page would also stop AddToAny’s assets from being loaded on that page. With Google’s continued push to have site owners improve their page speeds, reducing unnecessary bloat is increasingly becoming more important.
I’ve found I can get around this now with the help of the premium version of the Asset CleanUp plugin, but not everyone will want to pay to have access to something like that.
Anyhow, just a recommendation.
Good job on AddToAny as a whole, it’s a very nice plugin and generally does strike a fairly good balance between functionality and performance.