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/uploadsfolder, 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/uploadsusing “Optimize Everything Else”, but have it only scan and optimize that specific folder and not all the theme folders/plugin folders?Thanks,
Yaniv
-
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.
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.
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.
Ok. Is there a way to tell the plugin to skip over the theme and only scan the folders I specified in the options?
Nope, sorry.
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.
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.
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!
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; } }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?
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?
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!
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, you were probably right that it didn’t look like it was skipping them. When it actually works, it should say “Optimization skipped”
Thank you! Now it works like a charm!
Indeed, perfect! Thanks for the great support!
The topic ‘Optimizing only specific folders for "Optimize Everything Else"’ is closed to new replies.