Wordpress Topics

How To Get WordPress Featured Image and Display?

01/05/2023

Use the_post_thumbnail(); function to call featured images (featured Image) on the pages created during theme development in WordPress infrastructure.

Basic Post Thumbnail Display

the_post_thumbnail(); with the function, the post image can be displayed on the page in the simplest way.

the_post_thumbnail();

Display Cropped Post Thumbnail Sizes

While calling the page image, you can call it to the page within certain size patterns. the_post_thumbnail() to specify the dimensions of the images; You can use thumbnail, medium, medium_large, large, full or shop_thumbnail, shop_catalog, shop_single size patterns that come with Woocommerce within the function.

NOTE: add_image_size(); With the function, a custom visual dimension pattern can be created. This pattern is also the_post_thumbnail(); you can use in the function.

/* WordPress Default Sizes */

the_post_thumbnail ('thumbnail'); // Cropped 150x150
the_post_thumbnail ('medium'); // Cropped at Maximum 300 Pixels Width
the_post_thumbnail ('medium_large'); // Cropped at Maximum 768 Pixels Width
the_post_thumbnail ('large'); // Cropped at Maximum 1024 Pixel Width
the_post_thumbnail ('full'); // Image Uploaded Size

/* Sizes with Woocommerce */

the_post_thumbnail ('shop_thumbnail'); // Cropped 180x180
the_post_thumbnail ('shop_catalog'); // Cropped at Maximum 300 Pixels Wide
the_post_thumbnail ('shop_single'); // Cropped at Maximum 600 Pixels Wide

Source:

https://developer.wordpress.org/reference/functions/the_post_thumbnail/