Title: Partially exclude the jquery script from Autoptimize
Last modified: November 28, 2018

---

# Partially exclude the jquery script from Autoptimize

 *  Resolved [kevinc81](https://wordpress.org/support/users/kevinc81/)
 * (@kevinc81)
 * [7 years, 5 months ago](https://wordpress.org/support/topic/partially-exclude-the-jquery-script-from-autoptimize/)
 * Hi,
 * First of all, congratulations on your plugin which works really well.
 * Currently, in the scritps to exclude from Autoptimize I have: seal.js,js/jquery/
   jquery.js,leaflet.js
    However, I would like js/jquery/jquery.js to be partially
   excluded, not on my entire website. I would like jquery to be excluded from Autoptimize
   only in articles (parts of my website with the conditional marker ‘is_single()’)
   Is there a function for this (like for wp_rocket to disable its lazyload on specific
   parts of a website [https://docs.wp-rocket.me/article/16-disabling-lazyload-on-specific-posts](https://docs.wp-rocket.me/article/16-disabling-lazyload-on-specific-posts))?
 * I thank you in advance for your answer.
 * Best regards,
 * Kévin CAROL
    -  This topic was modified 7 years, 5 months ago by [kevinc81](https://wordpress.org/support/users/kevinc81/).
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fpartially-exclude-the-jquery-script-from-autoptimize%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 6 replies - 1 through 6 (of 6 total)

 *  Thread Starter [kevinc81](https://wordpress.org/support/users/kevinc81/)
 * (@kevinc81)
 * [7 years, 5 months ago](https://wordpress.org/support/topic/partially-exclude-the-jquery-script-from-autoptimize/#post-10929012)
 * 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](https://wordpress.org/support/users/kevinc81/).
 *  Plugin Author [Optimizing Matters](https://wordpress.org/support/users/optimizingmatters/)
 * (@optimizingmatters)
 * [7 years, 5 months ago](https://wordpress.org/support/topic/partially-exclude-the-jquery-script-from-autoptimize/#post-10936720)
 * sorry [@kevinc81](https://wordpress.org/support/users/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
 *  Thread Starter [kevinc81](https://wordpress.org/support/users/kevinc81/)
 * (@kevinc81)
 * [7 years, 5 months ago](https://wordpress.org/support/topic/partially-exclude-the-jquery-script-from-autoptimize/#post-10937568)
 * 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](https://wordpress.org/support/users/kevinc81/).
 *  Plugin Author [Optimizing Matters](https://wordpress.org/support/users/optimizingmatters/)
 * (@optimizingmatters)
 * [7 years, 5 months ago](https://wordpress.org/support/topic/partially-exclude-the-jquery-script-from-autoptimize/#post-10937800)
 * 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 🙂
 *  Thread Starter [kevinc81](https://wordpress.org/support/users/kevinc81/)
 * (@kevinc81)
 * [7 years, 5 months ago](https://wordpress.org/support/topic/partially-exclude-the-jquery-script-from-autoptimize/#post-10939600)
 * 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
 *  Plugin Author [Optimizing Matters](https://wordpress.org/support/users/optimizingmatters/)
 * (@optimizingmatters)
 * [7 years, 5 months ago](https://wordpress.org/support/topic/partially-exclude-the-jquery-script-from-autoptimize/#post-10939651)
 * you’re welcome Kévin, feel free to [leave a review of the plugin and support here](https://wordpress.org/support/plugin/autoptimize/reviews/#new-post)!
   🙂

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Partially exclude the jquery script from Autoptimize’ is closed to new
replies.

 * ![](https://ps.w.org/autoptimize/assets/icon-256X256.png?rev=2211608)
 * [Autoptimize](https://wordpress.org/plugins/autoptimize/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/autoptimize/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/autoptimize/)
 * [Active Topics](https://wordpress.org/support/plugin/autoptimize/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/autoptimize/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/autoptimize/reviews/)

## Tags

 * [exclude](https://wordpress.org/support/topic-tag/exclude/)
 * [jquery](https://wordpress.org/support/topic-tag/jquery/)

 * 6 replies
 * 2 participants
 * Last reply from: [Optimizing Matters](https://wordpress.org/support/users/optimizingmatters/)
 * Last activity: [7 years, 5 months ago](https://wordpress.org/support/topic/partially-exclude-the-jquery-script-from-autoptimize/#post-10939651)
 * Status: resolved