Wordpress cannot change default size of featured image - php

On my blog I want to add an ability to attach featured images to posts. However those images by default are extremely small (150x150px) also wordpress automatically compress the size of them.
I tried to set a larger size two ways: in settings->media I changed size of thumbnails to 750x550px also in functions.php added this code:
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 750, 550, true );
But it change nothing and I still get 150x150px images. How can I fix it?
I use wordpress version 4.9.4

Wordpress doesn't alter thumbnails of existing images in your media after changing the settings.
You can use this plugin to regenerate thumbnails of your existing images :
Wordpress Regenerate Thumbnails Plugin

Related

add_image_size hard crop not working for Already Uploaded Images

I have a Wordpress site with more than 1000 product images. I recently added 2 custom image sizes, product-medium and product-large.
So, when I upload a new product featured image, it is hard cropping the medium and large sizes perfectly.
However, the already uploaded images don't crop themselves to these 2 sizes. Any suggestions would be helpful.
I have tried using the regenerating thumbnails plugin, but it doesn't generate the 2 custom image sizes.
add_image_size( 'product-medium', 640, 480, true );
add_image_size( 'product-large', 1024, 576, true );
There is no error message. All the newly uploaded images show the 2 custom resolutions but the older ones don't.
You need to regenrate the thumbnails for the existing uploaded theme. You can also use wp-cli command to do the same :
wp media regenerate
You can also do the same with the plugins available in WordPress repository.
It will re-create the images with existing image sizes.

Add Custom Thumbnails on Custom Post Types in WordPress

I’ve set up a custom post type and I want the featured image to be cropped an resized for these types of post.
This code in functions.php correctly sizes and crops the featured images:
add_theme_support('post-thumbnails');
add_image_size( 'team_thumb', 719, 719, true);
And something like this makes it appear in the post:
<?php the_post_thumbnail('team_thumb'); ?>
But, the featured image that gets pulled from the page on the Essential Grid, or when sharing on social is still the full sized image.
What do I need to put in my custom post template (or elsewhere in the theme) to make the featured image associated with these custom posts the cropped/resized version?
Wordpress creates thumbnails when the file is uploaded. If you already uploaded images before adding "add_image_size" you must regenerate the thumbnail.
To do so you must use a plugin like "Force regenerate thumbnail" : https://fr.wordpress.org/plugins/force-regenerate-thumbnails/

Wordpress thumbnail sizes

In my functions.php i defined 2 dimensions i want to use on my site, small and custom-size and my file looks like this:
add_theme_support('post-thumbnails');
add_image_size('small', 120, '', true);
add_image_size('custom-size', 755, 220, true);
When i check my wp-content/uploads folder, except original image and 120px and 755px images i see several others dimensions (150px, 768px) and i was wondering why is that showing if i only have 2 dimensions (i am asking because i am on limited hosting and want to save on disk space because i host a lot of images).
Thank you!
There are generally three reasons that these other sizes could be showing up:
You had different thumbnail dimensions / image sizes in the past. Images are not re-created (or deleted) when you change image sizes, but you can use a plugin such as Regenerate Thumbnails to do this for you - just click the options it adds under the Tools menu, after you have changed your image sizes.
You have a plugin or theme installed that is creating additional image sizes. To track down what is doing this, you can either search through the files for add_image_size, or you could deactive plugins/change themes and then regenerate your thumbnails to see what the result is.
Wordpress has a new hidden image size for responsive images. This applies in the case of the 768px image. See this WP Core blog post for details. If you have no need for responsive images you could change the size that applies to this image using the instructions in that blog post (running eg. update_option('medium_large_size_w', '755') or even manually updating the option in the database - it's in the wp_options table). Again - regenerate thumbnails after doing this.

Wordpress downloaded images resizes itself

I am using wordpress and woocommerce. I have one problem, i have created a system with downloads steam market items (names and pictures) and then creates products. But I have one problem, downloaded images that are used for product are automaticly resized to a different resolutions : 150x113 300x225 300x300 425x280 and original one. So it takes 5x space, which is a problem for me. How do i disable or fix that resizing problem.
Thanks.
I found this article here by WP Mayor. Basically you remove the code that produces them.
function wpmayor_filter_image_sizes( $sizes) {
unset( $sizes['medium']);
unset( $sizes['large']);
unset( $sizes['wysija-newsletters-max']);
return $sizes;
}
add_filter('intermediate_image_sizes_advanced', 'wpmayor_filter_image_sizes');
function wpmayor_custom_image_sizes($sizes) {
$myimgsizes = array(
"image-in-post" => __( "Image in Post" ),
"full" => __( "Original size" )
);
return $myimgsizes;
}
add_filter('image_size_names_choose', 'wpmayor_custom_image_sizes');
place this in your functions.php file
UPDATE:
Also look here - Seems you just go to the media page, and set the other sizes to 0
By default, WordPress generates three sizes of each image that you upload. Themes and plugins can generate additional images sizes aswell.
First thing you should keep in mind is that the default image sizes are not harmful for your website.
If you already know this but you want to proceed anyway (or your space is really limited), you will need to do some steps to make Wordpress just keep the original image:
First you need to understand how many copies of an uploaded image
are generated by WordPress. You can check that using FTP client and
accesing /wp-content/uploads/ directory.
You can stop WordPress from generating default image sizes by
visiting Settings » Media in WordPress admin area. There you will
see default image sizes predefined by WordPress. You need to set
these sizes to 0 which will prevent WordPress from generating
default image sizes when you upload a new image.
Finally your theme might be generating other thumbnails (check it in
step 1), if this is the case look into your theme’s
functions.php file. Simply look for the code line containing:
add_image_size( 'homepage-thumb', 220, 180, true );
and
set_post_thumbnail_size( 150, 150 );
Note: WordPress uses the thumbnail image size for galleries and theme pages so they might break after you prevent their generation.
If you need further information I suggest you to check the original source of this post.
Hope this helps you.
MAKING YOUR IMAGES LIGHTER (JPEG COMPRESSION HOOK).
It don't take "5x space" but between x1.5 and x3 max, because other sizes are lighter, depending of their dimension and number of different sizes.
But you can make your images even much more lighter with this native hook:
add_filter( 'jpeg_quality', create_function( '', 'return 80;' ) );
You can tune the compression value replacing 80 by a number from 0 to 100. This hook doesn't compress your original image, but only all the others. If you want to use it you will need to paste it in the function.php file of your active child theme or theme.
IMAGES SETTINGS IN WOOCOMMERCE:
They are located in left menu Woocommerce > Settings > Products > Display. You can change all values to 0 (similar to Wordpress Media settings).
As the others answers suggested, you can unset somme of them programatically. Is better to keep thumbnails, because they are used to display images in the media library.

Allowing For Custom Images Sizes with WordPress's Gallery Shortcode

In WordPress 2.5 and up, there's a built in Gallery feature that allows the option to add an image gallery to a Post or Page on your WordPress blog. (Ref: http://codex.wordpress.org/Gallery_Shortcode)
You can use a size option to specify the thumbnail size you would like displayed. Valid values include "thumbnail", "medium", "large" and "full". The default is "thumbnail". The size of the images for "thumbnail", "medium" and "large" can be configured in WordPress admin panel.
ie. [gallery size="medium"]
My Question: I'm trying to hack up the [gallery] shortcode to allow for custom sizes at the time of input -- not trying to do this through the admin panel. I'd like to use something like, [gallery size="145x160"].
Rather then download a bloated plugin, I'd rather work with what's already there and I'm not sure where I need to go in my file structure to make the changes. I'm familiar with PHP but I'm afraid I'll make a change and then when I update future versions of WP, it will overwrite what I've set in motion.
Could someone help me out with this?
Thank you very much!
I know this is late, but I found this question trying to accomplish the same thing.
The Gallery does not have any built-in filters to allow this, so I developed a solution that works below.
In your theme's functions.php file, add the following lines of code:
remove_shortcode('gallery');
add_shortcode('gallery', 'custom_size_gallery');
function custom_size_gallery($attr) {
// Change size here - medium, large, full
$attr['size'] = 'medium';
return gallery_shortcode($attr);
}
This will interrupt the normal gallery call, revise the size being used, and then call the built-in WordPress gallery.
Wordpress crunch the images in several size when you upload them. So you can not get your given size image unless you set it to the admin panel before uploading the image.
But you can add additional image size:
add_image_size( 'sidebar-thumb', 120, 120, true ); // Hard Crop Mode
add_image_size( 'homepage-thumb', 220, 180 ); // Soft Crop Mode
add_image_size( 'singlepost-thumb', 590, 9999 ); // Unlimited Height Mode
More about add_image_size() on Codex

Categories