• Hi everyone,
    I would like to improve my website, when I go on GTMetrix it told me that i need to “Specify image dimensions”. What I had understood is the size is not specify when i call a picture “<img src=”, I should add “width:”” and height:”” “. So I would like to know which .php files or .css should I modify ? Same question for sidebar and widget associated.

    voyageur-du-dimanche.com

    Regards,
    CB

Viewing 4 replies - 1 through 4 (of 4 total)
  • I have the same issue.

    @cyrilb245, you can modify home.php, specifying image dimensions with a thing like that (sample):
    <img src="<?php echo leaf_get_post_image( null,null,true,null, 'large' ); ?>" width="xxx" height="xxx" alt="<?php the_title(); ?>" class="attachment-post-thumbnail wp-post-image">
    Use a child theme to do this, and search in the file where leaf_get_post_image is called.

    this is not the best practice, because we have tons of images in different sizes.

    @cagatay Belgen Yes I know that is not ideal, maybe a function in functions.php it would be better.
    Sorry I’m not a coder but I have modified those “callings” in home.php in that way and it works well, so I have shared my fix for OP @cyrilb245, or anyone interested in.
    Anyway, sizes are different for some categories maybe, not for every image. So you can have some categories in home page (the “problem” is only in home page, not for sidebar and widget), but I don’t think that you have more than 4-5 categories (do you have?) – beyond the fact that all categories can have featured image of the same size, it’s even better aesthetically.
    Also, the missing size is only for the first image of the category, the bigger one, not for the other three images in the category.
    A sample of what I have done:

    <?php if ( in_category (123) || in_category (45) ) { ?>
    <img src="<?php echo leaf_get_post_image( null,null,true,null, 'large' ); ?>" width="300" height="120" alt="<?php the_title(); ?>" class="attachment-post-thumbnail wp-post-image">
    <?php } elseif ( in_category (67) ) { ?>
    <img src="<?php echo leaf_get_post_image( null,null,true,null, 'medium' ); ?>" width="217" height="200"  alt="<?php the_title(); ?>" class="attachment-post-thumbnail wp-post-image">
    <?php } elseif ( in_category (89) || in_category (101)  ) { ?>
    <img src="<?php echo leaf_get_post_image( null,null,true,null, 'medium' ); ?>" width="200" height="300"  alt="<?php the_title(); ?>" class="attachment-post-thumbnail wp-post-image">
    <?php } ?>

    I don’t know if there’s a better way to write it.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Specify image dimensions GTMetrix’ is closed to new replies.