• Resolved aj

    (@batesajessica)


    I have AddToAny only active on posts, yet the js loads on every page and every custom post type. How can I prevent it from doing this?

    Thanks!

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

    (@micropat)

    AddToAny’s core JavaScript file loads by default so that AddToAny can display on posts loaded via Ajax, such as in an infinite scroll or similar.

    You can disable the file on non-posts by adding some PHP code to a “functionality” plugin such as the Code Snippets plugin:

    // Disables AddToAny's core script on non-posts
    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' );
    Thread Starter aj

    (@batesajessica)

    Thank you! I’ll give this a try and let you know if I have issues.

    Hi, I want to stop loading your script on the homepage. I tried this code on functions.php:

    // Disables AddToAny's core script on home page
    function addtoany_disable_script($script_disabled) {
        if ( is_front_page() ) {
            return true;
        } else {
    	    return $script_disabled;
        }
    }
    add_filter( 'addtoany_script_disabled', 'addtoany_disable_script' );

    but nothing happens. I cleared the cache but the script still loads…

    <link rel='stylesheet' id='addtoany-css'  href='*******/wp-content/plugins/add-to-any/addtoany.min.css?ver=1.15' type='text/css' media='all' />
    <style id='addtoany-inline-css' type='text/css'>
    <script type='text/javascript' src='*******/wp-content/plugins/add-to-any/addtoany.min.js?ver=1.1'></script>

    I don’t want the script bit neither the styles to appear on the homepage. Is this possible? Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘load script only on posts’ is closed to new replies.