Site logo

[Support request] Custom Featured Image Size on Home Page Using Block

Home Forums Support [Support request] Custom Featured Image Size on Home Page Using Block

Home Forums Support Custom Featured Image Size on Home Page Using Block

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #2085084
    Adam

    I have a custom image size that I use for my feature images. To achieve this, I added the following to my theme’s functions.php.

    add_action( 'init', function() {
        add_image_size( 'featured-crop', 1200, 630, true ); // 1200 width, 630 height, crop
    } );
    
    if ( has_post_thumbnail() ) { 
        the_post_thumbnail( 'featured-crop' ); 
    }

    I also added the following to allow the size to show in the WordPress admin. Not sure if this was needed, but I did it.

    add_filter( 'image_size_names_choose', 'my_custom_sizes' );
    function my_custom_sizes( $sizes ) {
        return array_merge( $sizes, array(
            'your-custom-size' => __( 'featured-crop' ),
        ) );
    }

    In Appearance-Customize-Layout-Blog I set the featured images to this custom size, and all is good on my Blog page (not Home page).

    I’m trying to add some blog posts to the top of my Home page also. I tried the Latest Posts block, in grid view, with featured image turned on, and with the custom size selected, but it shows the Large size instead.

    I also tried a Query Loop (my preferred choice since I can customize the look more), but I don’t have the option to change the image size for the featured image. I was hoping the setting used in Appearance-Customize-Layout-Blog would do the trick, but it does not.

    Is there any way, either through functions.php or CSS to force the featured image, when showing posts in a block, to use the featured-crop image size I created?

    #2085088
    Leo
    Staff
    Customer Support

    Hi there,

    The Latest Posts block or Query Loop block are both WP core blocks:
    https://wordpress.org/support/article/latest-posts-block/
    https://wordpress.org/support/article/query-loop-block/

    Therefore I would recommend checking with WP’s support team to see if there are filters available to use.

    Hope this helps 🙂

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.