Skip to content

Instantly share code, notes, and snippets.

@AlexWebLab
Last active April 24, 2017 06:19
Show Gist options
  • Save AlexWebLab/58035c8fbfe349fe6ac3b2741ab37b32 to your computer and use it in GitHub Desktop.
Save AlexWebLab/58035c8fbfe349fe6ac3b2741ab37b32 to your computer and use it in GitHub Desktop.
Resizing and showing images from ACF in WordPress theme development for page load performance optimisation
<?php
add_action( 'after_setup_theme', 'custom_image_sizes' );
function custom_image_sizes() {
add_image_size( 'image-1400px-wide', 1400 ); // 1400 pixels wide (and unlimited height)
add_image_size( 'image-700px-wide', 700 ); // 700 pixels wide (and unlimited height)
add_image_size( 'image-350px-wide', 350 ); // 350 pixels wide (and unlimited height)
}
<?php $image_src = wp_get_attachment_image_src( get_field('image_ID'), 'image-700px-wide' ); ?>
<!-- THIS WAY THE USER IS FREE TO UPLOAD AN IMAGE OF ANY SIZE (e.g.: from the smartphone) -->
<img src="<?php echo $image[0]; ?>" class="img-responsive product-image" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment