Change thumbnail size for default shortcode display

When using the “Default” shortcode for CPTUI-Extended, you have the option to output the featured image with each post. By default, CPTUI-Extended uses the “medium” thumbnail size. This may work fine for some, but if you’d prefer to use a different size, you can change it via a filter.

You will add the following snippets to your theme’s functions.php file or if you want, to a custom plugin build just for your own website.

function my_cptui_change_thumbnail_size( $original_size = '', $attributes, $post_id ) {
	return 'thumbnail';
}
add_filter( 'template_posts_thumbnail_size', 'my_cptui_change_thumbnail_size' );

With this snippet, we instead tell CPTUI-Extended to use the “thumbnail” image size, which is 150px by 150px. You can return whichever named image size is available, or an array of width and height pixel values. CPTUI-Extended will then pass the value to the `the_post_thumbnail()` function for final display.

Updated Dec 12, 2022 8:40 PM