there is, cfr. the example in autoptimize/autoptimize_helper.php_example;
add_filter('autoptimize_filter_noptimize','my_ao_noptimize',10,0);
function my_ao_noptimize() {
if (strpos($_SERVER['REQUEST_URI'],'no-autoptimize-now')!==false) {
return true;
} else {
return false;
}
}
where no-autoptimize-now is part of the URL of the page you’re trying to exclude.
hope this helps,
frank
Hello, guys
Tell me please, where exactly I should place this code?
well, you could use the code snippets plugin for that (to avoid littering files that could get overwritten).
frank
Frank, thank you for the advice.
I’ve tried to add code as snippet through plugin (replaced ‘no-autoptimize-now’ with ‘cart’ in one snippet and ‘checkout’ in another).
All pages of my site loaded blank.
Tried to paste code directly into autoptimize.php after line
// filter you can use to block autoptimization on your own terms
Same effect.
never-ever change a plugin-file. ever!
Now when using code snippets, if you have a blank page, that means there’s an error in the code somewhere. I quickly tested above code and it works as expected, so something went wrong when copy/pasting or adapting, probably a missing closing bracket or a missing single quote or something. carefully review, character per character, the code you have in code snippets.
frank
Thank you, Frank.
It helped.
If I need to exclude several pages, should I put all of them into the same snippet?
I tried to create separate snippets, but it caused 500 error.
one and the same snippet indeed, combining conditions like this;
if (
(strpos($_SERVER[‘REQUEST_URI’],’no-autoptimize-now’)!==false) ||
(strpos($_SERVER[‘REQUEST_URI’],’dont-autoptimize-me’)!==false) ||
(strpos($_SERVER[‘REQUEST_URI’],’never-autoptimize-this’)!==false)
) {
the linebreaks are just there for clarity 🙂
frank
Hi, I have one question, if I want to exclude my homepage should i replace this: ‘no-autoptimize-now’ with ‘www.mypage.com/’ or just the name of my homepage like ‘Homepage’.
you should instead do;
if (is_home()) {
return true;
} else {
return false;
}
frank