Adding a filter won’t work if the conditions aren’t right. The resize dimensions filter is definitely the one you want. The bypass filter only applies to compression, not resizing. So, what is the full code you tried?
Thread Starter
toto
(@toto)
Im using this code:
// Bypass ewww_image_optimizer for ‘SLIDER’ CPT
add_filter( ‘ewww_image_optimizer_resize_dimensions’, ‘ewww_custom_resize’ );
function ewww_custom_resize( $dimensions ) {
global $pagenow;
if ( ( ‘async-upload.php’ == $pagenow || ‘media-upload.php’ == $pagenow ) && false !== strpos( wp_get_referer(),’post_type=slider’ ) ) {
return array( 0, 0 );
}
return $dimensions;
}
And it works good!
If you upload image in CPT – slider, this code skip default setting in ewww to resize images and upload it in full size. 🙂 For all other uploads ewww resize images to default settings (1000x1000px).
But the code is not completed I need to make it, if you use bulk optimize all images – how to skip this folder ‘slider’. My CPT upload images in uploads/slider.
Is there a way to bypass resizing for CPT or for specific folder?
Thank you!
I just realized it isn’t really possible to bypass resizing based on the filename. So for the next release, I’m adding a second parameter, which will be the filename.
You would need to change your add_filter() call to this:
add_filter( ‘ewww_image_optimizer_resize_dimensions’, ‘ewww_custom_resize’, 10, 2 );
The 2 tells WP how many parameters your function expects. Then the function declaration needs to be like this:
function ewww_custom_resize( $dimensions, $file ) {
Then you can use strpos or preg_match on the $file variable, depending on whether you need to include/exclude sub-folders of the slider uploads folder.
FYI, the updated filter is on github: https://github.com/nosilver4u/ewww-image-optimizer
3.3 should be out in the next couple weeks otherwise.