Skip to content

Instantly share code, notes, and snippets.

@Matt-Welland
Created July 14, 2023 09:16
Show Gist options
  • Save Matt-Welland/3aef9cd61301d1ff2e28826ca78bd04e to your computer and use it in GitHub Desktop.
Save Matt-Welland/3aef9cd61301d1ff2e28826ca78bd04e to your computer and use it in GitHub Desktop.
Custom Image Sizes and Rendering of...
<?php
// Example setting some image sizes
add_image_size( 'hero', 1900, 940 );
add_image_size( 'square-large', 1200, 1200, true );
add_image_size( 'square', 600, 600, true );
add_image_size( 'featured-large', 2280, 860, true );
add_image_size( 'featured', 1140, 430, true );
add_image_size( 'image-block', 1140, 430, false );
add_image_size( 'teaser-large', 720, 480, true );
add_image_size( 'teaser', 360, 240, true );
add_image_size( 'teaser-nocrop', 360, 240, false );
<?php
// Example with ACF Image
$card_image = get_sub_field( 'image' );
echo esc_url( $card_image['sizes']['square'] );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment