Support » Plugin: AMP » Missing URL for attribute ‘srcset’ in tag ‘amp-img’.

  • Resolved kunaldabi


    Suddenly i can see large number of errors in my search console after activating this plugin. with error name Missing URL for attribute ‘srcset’ in tag ‘amp-img’.

    The error it showing in row number 407
    Please help me out.

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Plugin Contributor Ryan Kienstra


    Hi @kunaldabi,
    This workaround should prevent the srcset attribute from appearing at all when it is empty:

     * Prevents an empty 'srcset' attribute from appearing.
     * @param array  $attributes Image attributes.
     * @return array $attributes Filtered image attributes.
    add_filter( 'wp_get_attachment_image_attributes', function( $attributes ) {
    	if ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() && empty( $attributes['srcset'] ) ) {
    		unset( $attributes['srcset'] );
    	return $attributes;
    } );

    It’s a little strange that the featured image isn’t displaying on the AMP pages, including on the link above:

    <amp-img width="1024" height="683" src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" ...>

    It looks like there may be image lazy-loading on the site that outputs a featured image in AMP that’s not visible.

    • This reply was modified 9 months, 3 weeks ago by  Ryan Kienstra.
Viewing 1 replies (of 1 total)
  • The topic ‘Missing URL for attribute ‘srcset’ in tag ‘amp-img’.’ is closed to new replies.