Hi,
Maybe I wasn’t clear enough in my explanations
I would like to exclude from optimization js/jquery/jquery.js only for article pages (those parts of the website that have the conditional tag ‘is_single()’) )
Is there a function, to be placed in the functions.php file or elsewhere, of this type? :
function __deactivate_autoptimize_jquery_if_page()
{
if( is_single() ) {
add_filter( 'do_autoptimize_jquery', '__return_false' );
}
}
*this function is not correct, it is just to illustrate my request
Best regards,
Kévin CAROL
-
This reply was modified 7 years, 5 months ago by
kevinc81.
sorry @kevinc81; I didn’t receive a mail notification of your questoin. so yes, AO has a lot of filters and in your case you could use autoptimize_filter_js_exclude for that, something like this (warning; not tested):
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
Hi,
First of all, thank you for your answer.
It’s okay for the delay, I will have written a reminder in a few days if I hadn’t received a reply !
I added the missing “}” to your code and placed it in the functions.php file
Unfortunately this code is problematic, as soon as I validate the modification, I can no longer access any page of the administrator part of the site, the famous “white screen admin panel of death”. However, the site remained accessible as a visitor.
I had to restore a backup via my FTP FileZilla.
I don’t know what could have caused a bug so much in this code, I’m not a professional in this field…
I will therefore need your help again, and I thank you in advance.
Best regards,
Kévin CAROL
-
This reply was modified 7 years, 5 months ago by
kevinc81.
tested and works with the extra {;
add_filter('autoptimize_filter_js_exclude','jquery_toggle');
function jquery_toggle($in) {
if ( is_single() ) {
return $in.',js/jquery/jquery.js';
} else {
return $in;
}
}
fyi; I use the code snippets plugin to add code snippets and I tick the “Only run on site front-end” option, risks of white screens are minimal and if things go south simply renaming the code snippet plugin’s folder (wp-content/plugins/code-snippets) over FTP should bring things back to life 🙂
Hi,
In this way it has worked perfectly 😉
Thanks to your help, my website has saved more than 2 seconds of loading on pages where jquery is not necessary !
Thank you for everything
Best regards,
Kévin CAROL