Different sizes for highlighted images in wordpress!

1

I have a problem and I do not know how to solve it I tried everything and nothing!

I have a theme that uses 3 different images for the highlighted image, I'm using add_image_size to generate these three image sizes, but the problem is that the entire image I upload causes the 3 sizes!

If I post a gallery, 3 different image sizes will be generated for each image and this is consuming my server too much. I need it to generate only 3 images of the featured image.

Would you be able to do this?

follow my code of functions with add image size:

if ( function_exists( 'add_theme_support' ) ) {
    add_theme_support('post-thumbnails');
    add_image_size('ultimas-capa', 370, 240, true);
    add_image_size('capa-interno', 1020, 300, true);
    add_image_size('blog-capa', 780, 300, true);
}

if ( ! isset( $content_width ) ){
    $content_width = 800;
}

add_filter('image_size_names_choose', 'curioso_image_sizes');
function curioso_image_sizes($sizes) {

$mythemesizes = array(
    'blog-capa' => __('Imagem Postagem')
);

$sizes = array_merge($sizes, $mythemesizes);
return $sizes;
    
asked by anonymous 30.07.2015 / 21:47

1 answer

1

Your code seems to me to be incomplete. I'll base my answer on what I understand.

  • Add Image Size

    This method does what its name says: it adds a new image size. Any image is an image, including the featured images. You add support for thumbnails , and then add 3 new image sizes, regardless of whether they are thumbs or not. These two actions are independent things. Adding different sizes to the images can be done without the thumbs being activated. add_image_size() , in fact, is acting exactly as it should. If you want to add a unique size for the thumbs, WP has a method for that.

  • Set Post Thumbnail Size

    As the name says, this method arrow the size of the thumbnail. If you see the source of this method, you will see that

    function set_post_thumbnail_size( $width = 0, $height = 0, $crop = false ) {
        add_image_size( 'post-thumbnail', $width, $height, $crop );
    }
    

    The post_thumbnail parameter does exactly the filtering that (I think) you're looking for. You can include this parameter in your code, or use the above method (which I think is smarter as it will make it more readable)

  • I believe this will solve your problem. As I said, the code seems incomplete. Here has a relatively old article but has good information on the subject.

        
    10.08.2015 / 15:55