How to display your image with a new size on WordPress site open

How to display your image with a new size on WordPress site

Approved. Code works!
This is exactly the working code that is verified by the moderator or site administrators
Tested: WordPress 4.0+, PHP 5.6 +

In a previous post, we created a new size for your images on ours WordPress site.

How to add new image size WordPress open
How to add new image size WordPress
March 17, 2022
Roman-tk

Let’s display them in our template. Let’s start with the basic functions for working with post thumbnails

has_post_thumbnail() – allows check if thumbnail has been set for your post

the_post_thumbnail() – Allows output post thumbnail in cycle and set the size in the parameters

get_post_thumbnail_id() – Will help get post thumbnail id (example: 141)

get_the_post_thumbnail() – similar to has_post_thumbnail() function, which takes more parameters used when you need to get the data of this function for processing in PHP.

In our example we will use the most advanced function get_the_post_thumbnail().
We insert the code into the file single.php, depending on the output place, may change method getting ID for post thumbnail:

if (has_post_thumbnail(get_the_ID())) {
echo get_the_post_thumbnail(get_the_ID(), 'newsizeimagename')
}

newsizeimagename – сustom image size created by you

0

More

Leave a Reply

Your email address will not be published. Required fields are marked *

How many?: 22 + 22

lil-code© | 2022 - 2024
Go Top
Authorization
*
*
Registration
*
*
*
*
Password generation