I am trying to reduce the loading speed of my webpage. Google PageSpeed Insights tells me to optimize my images. In the following code, how can I set an image size so that if the uploaded image is 99999x99999px the rendered image is maximum 427px wide?
<?php
if ( has_post_thumbnail() ) {
echo '<a href="' . get_permalink($post->ID) . '" >';
the_post_thumbnail();
echo '</a>';
} else {
echo '<a href="' . get_permalink($post->ID) . '" ><img src="'. get_stylesheet_directory_uri() . '/img/fallback-featured-image.jpg" /></a>';}
?>
I would like Wordpress to handle this automatically so that I do not have to worry about cropping my images before I upload. It is also always nice to have the original size, but We do not want the user to wait for such a large image to load.