- This topic has 10 replies, 2 voices, and was last updated 6 years ago by Tom.
-
AuthorPosts
-
March 28, 2018 at 10:59 pm #534649Dean
Hi Tom.
I have just discovered the settings to change featured image sizes which can be found here (Customising > Layout > Blog).
This is causing some issues for us as every time a user enters new image sizes, it appears that every featured image is then cropped to the new sizes and saved in the uploads directory. Even when they are just experimenting with which size to use. Therefore we end up with multiple copies of images with different sizes. Most of which are never used.
This is bulking up our uploads directory and using up their upload quota more quickly. I understand you are doing this to please the page speed testers though ;-).
I have two thoughts:
1) Wouldn’t this be better done with a drop down box where you can just choose an existing size? This way no new image sizes would be added to the uploads directory.
2) Also, it appears that if only one size is set (width or height) then an image will not be cropped and added to the uploads directory. Could you confirm this is correct and intended?
Assuming 2 is correct, then as a temporary fix I am thinking to just hide the width box with css so the user can only adjust one and therefore not create any new images. Unless you have a better suggestion of how to prevent creating these new image sizes.
Thank you π
March 29, 2018 at 10:05 am #535327TomLead DeveloperLead DeveloperThis is definitely an issue unfortunately. It just involves having to clean up your directory once you find the size you want.
We tried to prevent too much build up by adding the “Apply” button.
A dropdown would be nice, but I’m sure we would get topics in here every day from people who need the images to be a specific size.
If you only select one size, the images should scale to that size, with the empty value becoming proportional.
March 29, 2018 at 7:37 pm #535758DeanHi Tom (@generate)
Can I just confirm that if we only use one size (width or height) then by scale above you mean it won’t add another image to the uploads directory?
In this case I will either hide just the width box, or both boxes with css so they cannot create new images.
Thanks for your quick reply as always :-).
March 29, 2018 at 10:36 pm #535832TomLead DeveloperLead DeveloperThe image resize will still create an image to the width or height you’ve specified.
If you don’t want to create new images, leave those image height/width values empty.
Then you can do something like this:
add_action('after_setup_theme', 'tu_add_image_sizes'); function tu_add_image_sizes() { add_image_size( 'large-thumbnail', 600, 600, true ); add_filter( 'generate_page_header_default_size', 'tu_set_image_size' ); } function tu_set_image_size() { return 'large-thumbnail'; }
April 2, 2018 at 10:36 pm #539331DeanHi Tom.
Thanks for providing the example above ;-). Looking at your example, it appears to me that it would adjust the featured image sizes for individual “Pages” (Home, contact, about etc). Is that correct? In our case I think individual pages and posts should remain as Auto Auto.
However, the blog page listing all the recent posts, and any archive / category / tag pages listing their associated posts should have a smaller default image size.
Could you tell me if the following would do the trick?
add_filter( 'generate_blog_image_attributes','tu_variable_image_sizes' ); function tu_variable_image_sizes( $atts ) { $atts[ 'width' ] = ''; $atts[ 'height' ] = 300; $atts[ 'crop' ] = false; // Return our options return $atts; }
I imagine the above would grab the wordpress “medium” image size. Make the image height 300 and the width would scale proportionately. Most importantly no new image size would be added to the uploads directory.
Thank you :-).
April 3, 2018 at 1:26 am #539431DeanUPDATE
So I setup a localhost version and tested this out. The above code I provided didn’t work without a conditional.
The below now appears to work for me. Doesn’t affect individual posts and pages, but uses the medium WP image size on the blog page, tag, category etc pages. And of course no new images added to the uploads directories :-).
add_filter( 'generate_blog_image_attributes','tu_variable_image_sizes' ); function tu_variable_image_sizes( $atts ) { if ( is_archive() || is_home() ) { $atts[ 'width' ] = 300; $atts[ 'height' ] = 300; $atts[ 'crop' ] = false; } return $atts; }
April 3, 2018 at 9:42 pm #540492TomLead DeveloperLead DeveloperAwesome! Thanks for sharing the code π
April 3, 2018 at 10:53 pm #540545DeanI couldn’t see a way to just set the medium WP image size. So I specified the width as 300 and height as 300, and without cropping, it seems to just use the medium size.
Unless you can recommend a better way to set the medium image, then I guess we are all done here to I will mark this as resolved.
Thanks again Tom.
April 3, 2018 at 10:55 pm #540548TomLead DeveloperLead DeveloperTechnically you should be able to do this, and it will apply to all featured images:
add_filter( 'generate_page_header_default_size', 'tu_medium_featured_images' ); function tu_medium_featured_images( $size ) { if ( ! is_singular() ) { return 'medium'; } return $size; }
However, there’s nothing wrong with the method you came up with π
April 3, 2018 at 11:05 pm #540554DeanThank you Tom. I prefer your way :-).
April 4, 2018 at 9:36 am #541129TomLead DeveloperLead DeveloperNo problem! π
-
AuthorPosts
- You must be logged in to reply to this topic.