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);
thanks for your answer so can i use this ?
function addtoany_disable_script_except_for_posts($script_disabled) {
if ( ! is_singular('post') ) {
return true;
} else {
return $script_disabled;
}
}
add_filter( 'addtoany_script_disabled', 'addtoany_disable_script_except_for_posts' );
That older code snippet you found is less reliable. The code snippet I posted above is recommended.
hey thanks a lot i added this
add_action( 'wp_enqueue_scripts', function() {
// Your conditional goes here. For example:
// Allow only on single posts (of any post type)
if ( is_singular('post') ) 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);
Hi!
This code snippet does not remove https://static.addtoany.com/menu/page.js for pages I do not need share buttons (like home page), other scripts – yes! Is there any variant to remove https://static.addtoany.com/menu/page.js? Google page speed metric fails here as Remove unused JavaScript, which of course I really do not need on pages I do not need sharing buttons!
Any suggestions?