# Minimum Size for Featured Images

> Stops posts from being published with a featured image smaller than the size you set, such as 1200 by 630 pixels, so social previews and hero images never look blurry.

- Type: PHP
- Runs: Run everywhere
- Category: [Content](https://wpide.com/library/category/content/)
- Tags: featured-image, editorial, publishing
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/content-featured-image-min-size/

## Code

```php
// Minimum featured image size in pixels.
$wpide_min_thumb_width  = 1200;
$wpide_min_thumb_height = 630;

add_filter( 'rest_pre_insert_post', function ( $prepared, $request ) use ( $wpide_min_thumb_width, $wpide_min_thumb_height ) {
    $post_id = (int) ( $prepared->ID ?? 0 );
    $status  = $request->get_param( 'status' ) ? $request->get_param( 'status' ) : get_post_status( $post_id );
    if ( ! in_array( $status, array( 'publish', 'future' ), true ) ) {
        return $prepared;
    }

    $image_id = null !== $request->get_param( 'featured_media' ) ? (int) $request->get_param( 'featured_media' ) : (int) get_post_thumbnail_id( $post_id );
    if ( ! $image_id ) {
        return $prepared;
    }

    $meta = wp_get_attachment_metadata( $image_id );
    if ( empty( $meta['width'] ) || ( $meta['width'] >= $wpide_min_thumb_width && $meta['height'] >= $wpide_min_thumb_height ) ) {
        return $prepared;
    }

    return new WP_Error(
        'wpide_featured_image_too_small',
        sprintf( 'The featured image is %1$d x %2$d pixels; please use one of at least %3$d x %4$d.', $meta['width'], $meta['height'], $wpide_min_thumb_width, $wpide_min_thumb_height ),
        array( 'status' => 400 )
    );
}, 10, 2 );
```

## Notes

Posts without a featured image are not affected; pair it with a "require featured image" rule if you need both.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Minimum Size for Featured Images" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
