• Resolved Daniel P.

    (@danidub)


    Hello, actually our website uses addtoany sharing buttons only with shortcode in posts, but we see that external calls and scripts are loaded in all website pages. This is affecting our WPO and site speed.

    Is there a way to limit loading the external scripts only on blog and posts pages? Is there any filter or action to do this? Maybe dequeue scripts if the page is not post?

    Thank you.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author micropat

    (@micropat)

    Hi Daniel,

    Yes, you can conditionally disable the main AddToAny script and dequeue the plugin’s CSS & JS like so:

    add_action( 'wp_enqueue_scripts', function() {
        // 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' );
    });

    Note that this will disable AddToAny’s dynamic use cases just as image sharing, shareable content loaded via Ajax, etc.

    Thread Starter Daniel P.

    (@danidub)

    Great, thank you.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Load addtoany external scripts requests only on posts’ is closed to new replies.