Viral WordPress Theme Homepage Image Size Problem

Share the joy
  •  
  •  
  •  

After finally working out how to add a featured image to the homepage for posts I ran into a problem where the images were appearing as full sized. This meant over 10Mb of image files were being downloaded when the homepage was loaded. There may be a way to select a lower resolution file but I couldnt find it, if there is let me know in the comments!

WordPress has a specific function that loads a thumbnail based on a given size.

After digging through the files for the Viral theme I narrowed the post code for the homepage down to /wp-content/themes/viral/template-parts/content.php

Glancing at this I could see that line 17

$viral_image = wp_get_attachment_image_src( get_post_thumbnail_id() , 'viral-blog-header' );

This gets the full size image of the file. Instead of this using the thumbnail function shown above I made the change to

$viral_image = wp_get_attachment_image_src( the_post_thumbnail( 'large' ) , 'viral-blog-header' );

Making this change lowers the file download to less than 1Mb.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.