Support

Account

Home Forums General Issues Different size for featured image

Solving

Different size for featured image

  • I am using this code which works fine to automatically set the featured image of a post.

    function acf_set_featured_image( $value, $post_id, $field  ){
        
        if($value != ''){
          //Add the value which is the image ID to the _thumbnail_id meta data for the current post
          add_post_meta($post_id, '_thumbnail_id', $value);
        }
     
        return $value;
    }
    
    // acf/update_value/name={$field_name} - filter for a specific field based on it's name
    add_filter('acf/update_value/name=fl_image', 'acf_set_featured_image', 10, 3);

    However, the problem with this is that the images I upload are quite large and they are being loaded in search results, making the page very slow.

    How can I modify this function to pick a smaller scaled version of the ACF image that was uploaded for the featured image?

    many thanks,
    Andy

  • This is not an ACF issue, this is an issue in your theme. The only thing you’re doing here is setting the attachment ID value. All sizes of an image have the same ID. Your theme is showing the full sized image. You’ll either need to edit your theme to show a smaller image up upload smaller images.

  • Hi, sorry for bringing this issue up again but I the problem here is ACF, not the theme.

    When I upload a photo using ACF field, I would like to set the ‘medium’ size being generated for the image, not the full scale image as seen by the code above.

    How could I do this please?

  • WP does not differentiate what size image is being set as the post thumbnail/featured image. All images sizes for any given image all have the same ID value, each image size does not get its own ID. Because of this it is not possible to insert a specific sized image as the featured image.

    What size image is shown on the site is dependent on how the image is added to the theme. There are several functions that can be used to add an image to a page, for example: https://developer.wordpress.org/reference/functions/the_post_thumbnail/

    
    the_post_thumbnail($size); 
    

    If size is not given in this function then it is assumed you want to show the “post-thumbnail” size, whatever that is.

    Your theme code can be adding the image in any number of ways, but it is there that you need to adjust the image size that is displayed and not when adding an image as the featured image for a post.

Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘Different size for featured image’ is closed to new replies.