Skip to content

Instantly share code, notes, and snippets.

@macgraphic
Created January 13, 2018 12:49
Show Gist options
  • Save macgraphic/d56bf6f3b4c7f75163a922037ef61ed0 to your computer and use it in GitHub Desktop.
Save macgraphic/d56bf6f3b4c7f75163a922037ef61ed0 to your computer and use it in GitHub Desktop.
<!-- Add this to your theme functions.php file -->
/*
* Enable support for Post Thumbnails on posts and pages.
*
* @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
*/
add_theme_support( 'post-thumbnails' );
// This theme uses a custom image size for featured images, displayed on "standard" posts.
if ( function_exists( 'add_theme_support' ) ) {
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 150, 150, true ); // default Post Thumbnail dimensions (cropped)
// additional image sizes
// delete the next line if you do not need additional image sizes
add_image_size( 'big-img', 870, 500, false ); // Size for default post full width
add_image_size( 'big-thumb', 539, 380, true ); // Size for 2-up thumbnails
add_image_size( 'arch-thumb', 418, 240, true ); // Size for 2-up thumbnails
}
$image_size = 'big-thumb';
$image_url = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID() ), $image_size );
$image_url = $image_url[0];
// Add our custom sizes to the Dashboard choices
add_filter( 'image_size_names_choose', 'my_custom_sizes' );
function my_custom_sizes( $sizes ) {
return array_merge( $sizes, array(
'big-img' => __( 'Big Image 870x500' ),
'big-thumb' => __( 'Big Thumb 539x380' ),
'arch-thumb' => __( 'Archive Thumb 418x240' ),
) );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment