• topfgartenwelt

    (@topfgartenwelt)


    My blog is online now and the lazy laoding / webp images are applied. But when testing the page with my mobile device I got the from Page Speed Insights the issue, that there is no explicit widht and height for the images. The issue was not flagged when I run the same test on my Desktop Device.

    I have now added the following code to my functions.php:
    function add_img_size($content){
    $pattern = ‘/]*?src=”(https?:\/\/[^”]+?)”[^>]*?>/iu’;
    preg_match_all($pattern, $content, $imgs);
    foreach ( $imgs[0] as $i => $img ) {
    if ( false !== strpos( $img, ‘width=’ ) && false !== strpos( $img, ‘height=’ ) ) {
    continue;
    }
    $img_url = $imgs[1][$i];
    $img_size = @getimagesize( $img_url );

    if ( false === $img_size ) {
    continue;
    }
    $replaced_img = str_replace( ‘<img ‘, ‘<img ‘ . $img_size[3] . ‘ ‘, $imgs[0][$i] );
    $content = str_replace( $img, $replaced_img, $content );
    }
    return $content;
    }
    add_filter(‘the_content’,’add_img_size’);`

    From here: https://webgaku.net/wordpress/add-img-size/

    The issue seems to be gone now.

    What do you think about it?

    Greetings Kathrin

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

Viewing 3 replies - 1 through 3 (of 3 total)
  • David

    (@diggeddy)

    Hi there,

    i checked the site and the webP images have width and height attributes.
    The only images that don’t are the ones being added by the Borlabs Cookie plugin.

    Thread Starter topfgartenwelt

    (@topfgartenwelt)

    Ok, thank you very much. Is the height and width there because of the php?

    Greetings Kathrin

    David

    (@diggeddy)

    Well the height and width attributes should be there by default …. so i am not sure if the process you have used to include webP images has changed that.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Images have no explicite width and heights’ is closed to new replies.