• Hi Frank,

    I’ve run into a bit of a brick wall. We are using AO on a project to optimize CSS only, using the inline and defer CSS option. However, this breaks a page delivered via an iframe.

    So, we tried to filter this iframed page from AO like so (in functions.php)…

    // add_filter('autoptimize_filter_noptimize','my_ao_noptimize',10,0);
    function my_ao_noptimize() {
    	if (strpos($_SERVER['REQUEST_URI'],'iframe-url-to-skip-from-AO')!==false) {
    		return true;
    	} else {
    		return false;
    	}
    }

    …but it’s not working: the inlined CSS just won’t go away. Moreover, when we tried a different URL to exclude (just to see if it was some sort of conflict with iframes) we ended up with the white screen of death and ultimately had to restore functions.php.

    Anyway, should this be working…?

    Best,
    AJ

    https://www.ads-software.com/plugins/autoptimize/

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Frank Goossens

    (@futtta)

    Let’s start with the easy stuff; this definitively should work (and does work for others, cfr. e.g. this support-thread)

    Now for the less obvious part; I’m not entirely sure I understand. Considering that a webpage with URL A can contain an iFrame with URL B:
    1. which of those URL’s (A and B) is on WordPress (and hence AO)?
    2. which URL are you trying to exclude with the noptimize-filter and what do you use as 2nd argument of the strpos-function?

    frank

    Thread Starter AJ @ WpFASTER.org

    (@ajm_1976)

    Sorry, I should have been more specific.

    An order form (URL B) is being loaded on a page (URL A) by way of an iframe. Both URLs are on WordPress, both on the same site/domain.

    The order form page (URL B) has a template, JavaScript and CSS exclusive to that page, so it ‘breaks’ when attempting to apply the global block of critical CSS to it. Ergo, we need to exclude that page being framed (URL B) from being Autoptimized.

    This URL (URL B) is what we’re trying to apply the filter to but it won’t take. If it should, then it should. I just need to make sure we’re doing it in a way compliant with AO (i.e. the above code).

    Given my elaboration, would you say the above code should be working?

    Thanks as always,
    AJ

    Plugin Author Frank Goossens

    (@futtta)

    Yep, that code should work, provided you have the correct string in the 2nd part of the strpos-function. Do take into account that PHP’s $_SERVER[“REQUEST_URI”] does not contain the full URL, but rather the path. So if the URL you want to exclude is https://domain.net/page/this-is-page-B, then you should match on “this-is-page-B” (or “B” or “page-B” or …).

    frank

    Thread Starter AJ @ WpFASTER.org

    (@ajm_1976)

    Okay Frank, thanks. I believe what was used was indeed the path, not the full URL, but I’ll have to double check that.

    AJ

    Plugin Author Frank Goossens

    (@futtta)

    One last remark; when using the path, do take into account that special characters might need encoding. You could always echo $_SERVER[“REQUEST_URI”] before the if-clause to see what PHP sees.

    Thread Starter AJ @ WpFASTER.org

    (@ajm_1976)

    Okay, Frank.

    Thanks again.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Excluding an Iframe Page From AO via Filter’ is closed to new replies.