Have you noticed number of warning increasing for your sites AMP in Google Search Console regarding Image size smaller than recommended size?

Did you confused what has changed over night in your site?

Nothing to get confused, Google has changed its minimum recommended size for the images in Structured Data.

 

Oh My God! What is it and how do I fix it?

If you are using Official AMP plugin then its pretty simple to fix it. Yes it is…

Add the below code to your themes functions.php or in your custom plugin.

/**
* Filter AMP Metadata and set Image to 1200 width.
*
* @param array $metadata Metadata.
*
* @return array Metadata
*/
function d9_amp_filter_metadata_image( $metadata ) {
    if ( ! empty( $metadata['image']['url'] ) && 1200 > (int) $metadata['image']['width'] ) {
        $new_height = intval( ( $metadata['image']['height'] / $metadata['image']['width'] ) * 1200 );
        $url = explode( '?', $metadata['image']['url'] ); }

        $metadata['image'] = array(
            '@type'  => 'ImageObject',
            'url'    => $url,
            'width'  => 1200,
            'height' => $new_height,
        );
    }

    return $metadata;
}

add_filter( 'amp_post_template_metadata', 'd9_amp_filter_metadata_image', 11);

 

After updating your files with the above code, go to your AMP section of Google Search Console and find the `Image size smaller than recommended size` warning. When you are on the warning page, you can see the validate fix button, use it to re-validate your site content.

 

Once Google started the validation process it will take few days or weeks to validate the entire content which is completely based on number of articles you have published, but the warning will progressively reduce.