Title: Optimizing only specific folders for &quot;Optimize Everything Else&quot;
Last modified: August 30, 2016

---

# Optimizing only specific folders for "Optimize Everything Else"

 *  Resolved [Yaniv](https://wordpress.org/support/users/yaniv691/)
 * (@yaniv691)
 * [10 years, 10 months ago](https://wordpress.org/support/topic/optimizing-only-specific-folders-for-optimize-everything-else/)
 * Hi,
 * I have image thumbnails that are generated on the fly by my theme (Envision) 
   using Aqua Resizer. These thumbnails are located in the `wp-content/uploads` 
   folder, but are not picked up by EWWW when doing a scan and optimize using “Optimize
   Media Library”.
 * How can I scan and optimize `wp-content/uploads` using “Optimize Everything Else”,
   but have it only scan and optimize _that specific folder_ and not all the theme
   folders/plugin folders?
 * Thanks,
    Yaniv
 * [https://wordpress.org/plugins/ewww-image-optimizer/](https://wordpress.org/plugins/ewww-image-optimizer/)

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

 *  Plugin Author [nosilver4u](https://wordpress.org/support/users/nosilver4u/)
 * (@nosilver4u)
 * [10 years, 10 months ago](https://wordpress.org/support/topic/optimizing-only-specific-folders-for-optimize-everything-else/#post-6300444)
 * Sure, just put the full system path to the wp-content/uploads/ folder into the‘
   Folders to Optimize’ setting. It will skip over anything it has already optimized.
   If Aqua Resizer uses the built-in WP Image Editor functions, future images will
   be optimized automatically, but I don’t have any first-hand experience with that
   particular resizing library.
 *  Thread Starter [Yaniv](https://wordpress.org/support/users/yaniv691/)
 * (@yaniv691)
 * [10 years, 10 months ago](https://wordpress.org/support/topic/optimizing-only-specific-folders-for-optimize-everything-else/#post-6300459)
 * That’s what I did, but EWWW also scans other folders (e.g. wp-content/themes)
   and optimizes the images found there. I don’t want it to optimize all images,
   just images only found in folders I specify. This is important to me because 
   I use EWWW Cloud with prepaid credit and don’t want to spend credits on images
   I don’t need optimized.
 *  Plugin Author [nosilver4u](https://wordpress.org/support/users/nosilver4u/)
 * (@nosilver4u)
 * [10 years, 10 months ago](https://wordpress.org/support/topic/optimizing-only-specific-folders-for-optimize-everything-else/#post-6300464)
 * I see how that can be confusing, but it only scans your currently active theme,
   it does not scan the entire wp-content/themes/ folder.
 *  Thread Starter [Yaniv](https://wordpress.org/support/users/yaniv691/)
 * (@yaniv691)
 * [10 years, 10 months ago](https://wordpress.org/support/topic/optimizing-only-specific-folders-for-optimize-everything-else/#post-6300466)
 * Ok. Is there a way to tell the plugin to skip over the theme and only scan the
   folders I specified in the options?
 *  Plugin Author [nosilver4u](https://wordpress.org/support/users/nosilver4u/)
 * (@nosilver4u)
 * [10 years, 10 months ago](https://wordpress.org/support/topic/optimizing-only-specific-folders-for-optimize-everything-else/#post-6300473)
 * Nope, sorry.
 *  Thread Starter [Yaniv](https://wordpress.org/support/users/yaniv691/)
 * (@yaniv691)
 * [10 years, 10 months ago](https://wordpress.org/support/topic/optimizing-only-specific-folders-for-optimize-everything-else/#post-6300493)
 * Thanks. Please consider about adding this as a feature in your future updates
   of the plugin (and the cloud plugin as well). Every time I’ll update my theme
   I’ll have to re-optimize all the images again, because I’ll be getting the original
   images from the update.
 * It would be great if I could just quickly optimize my specified folders.
 *  Plugin Author [nosilver4u](https://wordpress.org/support/users/nosilver4u/)
 * (@nosilver4u)
 * [10 years, 10 months ago](https://wordpress.org/support/topic/optimizing-only-specific-folders-for-optimize-everything-else/#post-6300699)
 * I realized this morning that there is a solution for your problem. The core function
   has this filter:
 * `apply_filters( 'ewww_image_optimizer_bypass', false, $file );`
 * $file is the full path to the file, and with that you could check to see if the
   file is within the themes folder (or whatever other folder you want to skip),
   and then return TRUE if it is.
 * If you need a more concrete example, let me know.
 *  Thread Starter [Yaniv](https://wordpress.org/support/users/yaniv691/)
 * (@yaniv691)
 * [10 years, 10 months ago](https://wordpress.org/support/topic/optimizing-only-specific-folders-for-optimize-everything-else/#post-6300700)
 * Wow, that’s great! Can you please give me a complete example of how I would skip
   the theme’s folder? Also, where do I put the code?
 * Thanks!
 *  Plugin Author [nosilver4u](https://wordpress.org/support/users/nosilver4u/)
 * (@nosilver4u)
 * [10 years, 10 months ago](https://wordpress.org/support/topic/optimizing-only-specific-folders-for-optimize-everything-else/#post-6300705)
 * You would create file with a name like ewww-skip-theme.php and put it in the 
   plugins folder (no need for a subfolder unless you prefer it that way). The entirety
   of the plugin would look something like this (and adjust the value of $folder_to_skip
   to your themes/ folder):
 *     ```
       <?php
       /*
       Plugin Name: EWWW Skip Theme Scanning
       Version: .1
       */
   
       add_filter( 'ewww_image_optimizer_bypass', 'ewww_skip_theme', 10, 2 );
       function ewww_skip_theme ( $bypass, $filename ) {
         $folder_to_skip = '/var/www/wordpress/wp-content/themes/';  // change this line with the appropriate path to the themes/ folder
         if ( preg_match( "/^$folder_to_skip/", $filename ) ) {
           return true;
         } else {
           return false;
         }
       }
       ```
   
 *  Thread Starter [Yaniv](https://wordpress.org/support/users/yaniv691/)
 * (@yaniv691)
 * [10 years, 10 months ago](https://wordpress.org/support/topic/optimizing-only-specific-folders-for-optimize-everything-else/#post-6300706)
 * Thanks for that, I really appreciate your high level of support!
 * But EWWW is still scanning and optimizing images in the themes folder.
 * I’m sure I entered the path to the theme’s folder correctly because I echoed 
   it in the theme skip plugin and saw it returned the path that EWWW is scanning
   and optimizing during “Scan and Optimize”. How can it be fixed?
 *  Plugin Author [nosilver4u](https://wordpress.org/support/users/nosilver4u/)
 * (@nosilver4u)
 * [10 years, 10 months ago](https://wordpress.org/support/topic/optimizing-only-specific-folders-for-optimize-everything-else/#post-6300707)
 * It will still scan the folder, the bypass happens right before the images get
   optimized. In your case though, the images are probably already optimized, unless
   you installed a fresh copy of your theme?
 *  [Kyle](https://wordpress.org/support/users/kyleheldskybounddesignscom/)
 * (@kyleheldskybounddesignscom)
 * [10 years, 10 months ago](https://wordpress.org/support/topic/optimizing-only-specific-folders-for-optimize-everything-else/#post-6300726)
 * Hi nosilver4u,
 * Loving the plugin and running it on lots of sites, but I am not having any luck
   with the folder skipping script above.
 * Is it compatible with EWWW Cloud? I’m attempting to use the following, but upon
   bulk scan it’s finding and optimizing theme files anyway. I tried both specifying
   the sub-folder and not.
 *     ```
       add_filter( 'ewww_image_optimizer_bypass', 'ewww_skip_theme', 10, 2 );
       function ewww_skip_theme ( $bypass, $filename ) {
         $folder_to_skip = '/nas/wp/www/cluster-42062/exampleinstall/wp-content/themes/enfold/';  // change this line with the appropriate path to the themes/ folder
         if ( preg_match( "/^$folder_to_skip/", $filename ) ) {
           return true;
         } else {
           return false;
         }
       }
       ```
   
 * Appreciate any insight!
 *  Plugin Author [nosilver4u](https://wordpress.org/support/users/nosilver4u/)
 * (@nosilver4u)
 * [10 years, 10 months ago](https://wordpress.org/support/topic/optimizing-only-specific-folders-for-optimize-everything-else/#post-6300729)
 * Tested it out myself, and realized there’s a problem with the pattern matching.
   The themes path has slashes in it, and we’re using those as the start and end
   of our pattern, which will not work. Replace those with pipes |, and it will 
   work, like so:
 *     ```
       add_filter( 'ewww_image_optimizer_bypass', 'ewww_skip_theme', 10, 2 );
       function ewww_skip_theme ( $bypass, $filename ) {
         $folder_to_skip = '/nas/wp/www/cluster-42062/exampleinstall/wp-content/themes/enfold/';  // change this line with the appropriate path to the themes/ folder
         if ( preg_match( "|^$folder_to_skip|", $filename ) ) {
           return true;
         } else {
           return false;
         }
       }
       ```
   
 * [@yaniv691](https://wordpress.org/support/users/yaniv691/), you were probably
   right that it didn’t look like it was skipping them. When it actually works, 
   it should say “Optimization skipped”
 *  Thread Starter [Yaniv](https://wordpress.org/support/users/yaniv691/)
 * (@yaniv691)
 * [10 years, 10 months ago](https://wordpress.org/support/topic/optimizing-only-specific-folders-for-optimize-everything-else/#post-6300730)
 * Thank you! Now it works like a charm!
 *  [Kyle](https://wordpress.org/support/users/kyleheldskybounddesignscom/)
 * (@kyleheldskybounddesignscom)
 * [10 years, 10 months ago](https://wordpress.org/support/topic/optimizing-only-specific-folders-for-optimize-everything-else/#post-6300731)
 * Indeed, perfect! Thanks for the great support!

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

The topic ‘Optimizing only specific folders for "Optimize Everything Else"’ is closed
to new replies.

 * ![](https://ps.w.org/ewww-image-optimizer/assets/icon-256x256.png?rev=1582276)
 * [EWWW Image Optimizer](https://wordpress.org/plugins/ewww-image-optimizer/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/ewww-image-optimizer/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/ewww-image-optimizer/)
 * [Active Topics](https://wordpress.org/support/plugin/ewww-image-optimizer/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/ewww-image-optimizer/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/ewww-image-optimizer/reviews/)

 * 15 replies
 * 3 participants
 * Last reply from: [Kyle](https://wordpress.org/support/users/kyleheldskybounddesignscom/)
 * Last activity: [10 years, 10 months ago](https://wordpress.org/support/topic/optimizing-only-specific-folders-for-optimize-everything-else/#post-6300731)
 * Status: resolved