Snippets: Custom Post Type Image Sizes

The Total theme makes it easy to add new image sizes under the Theme Panel > Image Sizes admin dashboard so you can better control the display of your custom post type featured images. The snippet below is an example of how to add a new options for your custom post type entries and singular post. Simply change {post_type} with your post type name (replacing the brackets). Important: This will only work if the theme is displaying the post types some plugins have custom layouts for post types so keep this in mind.

// Add new {post_type} image size (replace {post_type} with your cpt name)
add_filter( 'wpex_image_sizes', function my_image_sizes( $sizes ) {

	// Add new size for archive entries
	$sizes['{post_type}_entry'] = array(
		'label' => __( 'Post Type Name', 'wpex' ),
		'width' => '{post_type}_entry_width',
		'height' => '{post_type}_entry_height',
		'crop' => '{post_type}_entry_crop',
	);

	// Add new size for singular posts
	$sizes['{post_type}_single'] = array(
		'label' => __( 'Post Type Name', 'wpex' ),
		'width' => '{post_type}_single_width',
		'height' => '{post_type}_single_height',
		'crop' => '{post_type}_single_crop',
	);

	// Return sizes
	return $sizes;

}, 9999 );
All PHP snippets should be added via a child theme's functions.php file.