• Resolved Flint

    (@flintstoned)


    Dear SG,

    I saw the topic about how to exclude scripts from minifying but how would I do it for combining JS? In the exclude list already provived in the plugin, the script isn’t listed so I want to exclude it via functions.php

    Please advice.

    Kind regards,

Viewing 1 replies (of 1 total)
  • Plugin Support daniellaivanova

    (@daniellaivanova)

    Hello,

    Excluding a particular script from the JS combination depends on whether the script itself is enqueued, external, or inline.

    For your convenience, I am providing you with the code you should use in each of these cases:

    • For Enqueued scripts

    add_filter( 'sgo_javascript_combine_exclude', 'js_combine_exclude' );
    function js_combine_exclude( $exclude_list ) {
    $exclude_list[] = 'script-handle';
    $exclude_list[] = 'script-handle-2';
    return $exclude_list;
    }

    • For External scripts

    add_filter( 'sgo_javascript_combine_excluded_external_paths', 'js_combine_exclude_external_script' );
    function js_combine_exclude_external_script( $exclude_list ) {
    $exclude_list[] = 'script-host.com';
    $exclude_list[] = 'script-host-2.com';
    return $exclude_list;
    }

    • For Inline scripts

    add_filter( 'sgo_javascript_combine_excluded_inline_content', 'js_combine_exclude_inline_script' );
    function js_combine_exclude_inline_script( $exclude_list ) {
    $exclude_list[] = 'first few symbols of inline content script';
    return $exclude_list;
    }

    You should make sure to add the respective code into the active theme’s functions.php file.

    Best Regards,
    Daniela Ivanova

Viewing 1 replies (of 1 total)

The topic ‘Exclude JS scripts from combining via functions.php’ is closed to new replies.