• Resolved Tom

    (@narlytom)


    I wonder if it is possible to exclude js on certain pages only.

    I have a handful of pages that require js to be excluded, but the rest of the site doesn’t require this.

    I have used a workaround to disable autoptimise on these pages by adding this to the pages code:
    <!– <xsl:stylesheet –>

    This makes the pages work, but makes them VERY slow

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

    (@optimizingmatters)

    It is, with a couple of lines of code hooking into AO’s API. Example;

    
    add_filter('autoptimize_filter_js_exclude','jquery_toggle');
    function jquery_toggle($in) {
        if ( is_single() ) {
            return $in.',js/jquery/jquery.js';
    	} else {
            return $in;
        }
    }

    hope this helps,
    frank

    Thread Starter Tom

    (@narlytom)

    Hi, thanks so much for that, but I’m afraid I’m too ignorant to understand exactly how to implement this.

    Do I add this to functions.php? And then do I need to add some code on the pages where I want to implement it? Or do I need to modify this code to specify the pages?

    For example – if I want to exclude js/jquery/jquery.js on /test-page and /homepage – what do I need to do?

    Thank you again

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    best way forwards would be to ask someone who knows (some) PHP to do it for you, but if not try adding below code using the code snippets plugin:

    add_filter('autoptimize_filter_js_exclude','jquery_toggle');
    function jquery_toggle($in) {
        if ( is_front_page() || strpos( $_SERVER['REQUEST_URI'], 'test-page' ) !== false ) {
            return $in.', js/jquery/jquery.js';
    	} else {
            return $in;
        }
    }
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Exclude js from autoptimize on certain pages only’ is closed to new replies.