How to Fix: Image size smaller than recommended size
Recently, Google AMP issues report appeared in Google Search Console with the message Image size smaller than recommended size. What this warning means and is there a way to fix it?
Today I am going to share a very useful post which will help you to fix the image size smaller than recommended size warning in your Google Search Console by adding the simple code.
To fix the smaller image size related warning in Google Search Console, either you need to have at least 1 image with at least minimum of 1200px wide. If your website has lots of posts and pages, then follow the following steps for the permanent fix.
Rules for Images in AMP – Updated
- Only a marked-up image that directly belongs to the article should be specified.
- Images should be at least 1200 pixels.
- Every page must contain at least one image (1200 pixels). Google will pick the best image to display in Search results based on the aspect ratio and resolution.
How To Fix: Image Size Smaller Than Recommended Size
Follow the below steps to fix the image size smaller than recommended size.
Step 1. Create a large (>= 1200 pixels wide) amp_preview_image.jpg image file and upload it inside your project folder wp-content/uploads/ directory that you’ve just created like: wordpress/wp-content/uploads/amp_preview_image.jpg.
Step 2. Copy the below php code add inside your functions.php from your current activated theme.
Note: Please note that below code will only work with the official WordPress AMP plugin only. The following code is not compatible and also not tested with the other WordPress AMP plugins.
<?php
/**
* Image size smaller than recommended size Warning in Search console.
*
* @param $metadata string.
*
* @return string Image size in structure data to fix the console error.
*/
function amp_modify_json_metadata( $metadata, $post ) {
if ( 'post' === $post->post_type ) {
// set custom article image
// if original is missing/not found
// or if featured image width or height dimension is smaller than 1200 pixels
// you must place "amp_preview_image.jpg" in /wp-content/uploads/
// also you can change image extension to .png or any other instead of .jpg defined below
// also UPDATE IMAGE height AND width NUMBERS TO MATCH YOUR GENERIC IMAGE SIZE (in pixels)
$countArticleImages = isset( $metadata['image'] ) ? count( $metadata['image'] ) : 0;
if (
$countArticleImages == 0
||
( ( $metadata['image']['width'] >= $metadata['image']['height'] )
&& ( $metadata['image']['width'] < 1200 ) )
||
( ( $metadata['image']['width'] < $metadata['image']['height'] )
&& ( $metadata['image']['height'] < 1200 ) )
) {
$metadata['image'] = array(
'@type' => 'ImageObject',
'url' => WP_CONTENT_URL . '/uploads/amp_preview_image.jpg',
'height' => 1200,
'width' => 1200,
);
}
}
return $metadata;
}
add_filter( 'amp_post_template_metadata', 'amp_modify_json_metadata', 10, 2 );
If you are using the AMP for WP – Accelerated Mobile Pages WordPress plugin in your site, then follow the below steps to fix the image size smaller than recommended size warnings in your Google Search Console.
Copy and paste the below code at the end of your functions.php file and save it.
<?php
/**
* Image size smaller than recommended size Warning in Search console.
*/
if ( ! function_exists( 'ampforwp_sd_feature_image_guidlines' ) ) {
function ampforwp_sd_feature_image_guidlines( $metadata ) {
if ( isset( $metadata['image']['width'] ) && $metadata['image']['width'] <= 1200 ){
$image_width = 1280;
$image_height = 720;
$image = ampforwp_aq_resize( $metadata['image']['url'],
$image_width, $image_height, true, false, true );
$image_url = $image[0];
$metadata['image']['url'] = $image_url;
$metadata['image']['width'] = $image_width;
$metadata['image']['height'] = $image_height;
}
return $metadata;
}
}
add_filter( 'amp_post_template_metadata', 'ampforwp_sd_feature_image_guidlines', 22, 1 );
Step 3. After followed the above steps login to your Google Search Console and navigate to the AMP section from left sidebar section.
Step 4. Now open the “Image size smaller than recommended size” section and validate your changes.
Step 5. Now allow Google to validate your changes. It will take 2-4 days normally to validate your changes. Once Google will validated and if found no warning, then you will see the message like below screenshot.
If you still getting the Image size smaller than recommended size warning in your Google Search Console, then add feel free to your comment in the below comment section, I am happy to help you to fix image size smaller than recommended size warning.