Different sizes for images highlighted in wordpress!

Asked

Viewed 448 times

2

I’m in trouble and I don’t know how to fix it I’ve tried everything and nothing!

I have a theme that uses 3 different images for the highlighted image, I’m using the add_image_size to generate these three image sizes, plus the problem is that the entire image I upload generates 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 him to generate only 3 images of the featured image.

You could do that?

follow my functions code 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;

1 answer

2

Your code seems to me to be incomplete. I will base my answer on what I understood.

  1. Add Image Size

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

  2. Set Post Thumbnail Size

    As the name says, that method arrow the thumbnail size. 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 parameter post_thumbnail does exactly the filtering that (I think) you seek. You can include this parameter in your code, or use the above method (which I think is smarter because it will make it more readable)

I believe that solves your problem. As I said, the code seems incomplete. Here has a relatively old article but which has good information on the subject.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.