• Resolved christian70

    (@christian70)


    Hi,

    is there any way to remove actions that load JS and CSS files where useless? Because they are loaded everywhere in the site in spite of the fact share features are used or not.

    Thanks.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Heateor Support

    (@heateor)

    Hi,

    To check if share icons are there whenever someone loads your web page in their browser, would be a performance overhead as the icons might be there because of shortcode or/and widget.

    However, you can add following code in the functions.php file of active theme or use this code as a plugin, to prevent the Javascript and CSS files from loading at certain web pages. This code prevents the loading of plugin’s CSS and Javascript at the post with WordPress Post ID 1.

    /**
    * Initialization
    */
    function heateor_sss_custom_init() {
    add_action( 'wp_enqueue_scripts', 'heateor_dequeue_js_css' );
    }
    add_action( 'init', 'heateor_sss_custom_init' );

    /**
    * Dequeue the CSS and Javascript files of Sassy Social Share
    */
    function heateor_dequeue_js_css() {
    global $post;
    // put your condition here
    if ( is_object( $post ) && $post->ID == 1 ) {
    wp_dequeue_style( 'heateor_sss_frontend_css' );
    wp_dequeue_script( 'heateor_sss_sharing_js' );
    }
    }

    Thread Starter christian70

    (@christian70)

    Thank you, your script has been very useful. Now I can enqueue plugin scripts only on single posts where share feature is implemented.

    Plugin Author Heateor Support

    (@heateor)

    You’re welcome. May I ask you to leave a review?

    Thread Starter christian70

    (@christian70)

    Surely I’m gonna do it. Thanks.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Remove scripts when not used’ is closed to new replies.