How to Add Custom post Thumbnails in WordPress Theme without Plugin - php

On my WordPress website, I have a blog page that contains 4 posts, and each post has an image of size 1080x900 px. I want to show this image as a thumbnail of 350x300px on the WordPress site.
How can I add custom thumbnail size in the function.php file and what is the next step to do?

You can use
add_theme_support( 'post-thumbnails' );
add_image_size( 'custom-size', 350, 300, true );
Images will be available as a thumb in that size after you regenerate media.
For more info: https://developer.wordpress.org/reference/functions/add_image_size/

Related

Wordpress resizing post thumbnails

I wanna resize post thumbnail in Wordpress. So I use that function: get_the_post_thumbnail($onepost->ID, array(234, 156)); But I recive images with size 300x189. Why is this happens?
You best bet it to add your thumbnail size by using at add_image_size function, then call that new thumnail in your function:
In your functions.php:
add_image_size( 'custom-thumb', 234, 156 );
In your template file or wherever you're calling the thumbnail:
the_post_thumbnail( 'custom-thumb' );
Note that you will probably have to regenate your thumbnails after you do this as thumbnails are created when you upload the image, thus all images you uploaded won't have this custom thumbnail size. Here is a good plugin for that:
https://wordpress.org/plugins/regenerate-thumbnails/

Featured Image on Wordpress

I have a little problem... when I want to show the featured image on my posts, the chosen size isn't working (the photo is shown in it's own size). And I want the featured Image to be shown in the same width as the post total width but I have no clue!
This is the code I'm using in the PHP section
if ( function_exists( 'add_theme_support' ) ) add_theme_support( 'post-thumbnails' ); set_post_thumbnail_size(640, 205);
My question is... where do I have to put this code?
<?php add_theme_support( 'post-thumbnails' );?>
And what would be the css I have to use to show it in the same width as the post total width?
Thanks
Put the php code add_theme_support( 'post-thumbnails' ); on functions.php under the theme directory.
WordPress cutting thumbnails while uploading the file, so you have to enable the feature first then upload the image.
Put this code add_theme_support( 'post-thumbnails' ); in function.php file
Select Post option,at right side bar corner,you will find the option as Featured images changes and updates,select and update the image which you require.
Else try with this Code format:
the_post_thumbnail();
set_post_thumbnail_size( 50, 50);`add_image_size( 'single-post-thumbnail', 590, 180 );

Wordpress 3.8 add_image_size( ) not working

i am trying to create my first wordpress theme and i came now to a problem i can't seem to solve.
Due to the design of the theme, i would like to have featured images on every post, but they would need to be all the same size.
On my functions.php i have enabled the feature images, set a size and even tried to add custom size, but nothing is working as i wanted.
My code looks like this:
function.php:
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 200,200, true);
add_image_size( 'feat', 200, 200, true );
then on my content.php:
<?php the_post_thumbnail('feat'); ?>
The images resize, but they don't crop. It makes the bigger side of the image equal to 200, but still keeps the original aspect ration.
Any ideas of what i'm doing wrong?
Maybe it happens because you had added add_image_size before you uploaded your images.
Try to delete and upload images again or download Regenerate Thumbnails plugin and regenerate all your images in media library.

How can i use the uploaded image as featured image in wordpress post?

I just upload 250x250 resolution images for all of my post. When i set one of the image as featured its getting cropped into 250x198.
I just want to use the uploaded image itself without any modification. I have tried Thumbnail Re-builder plugin,even it doesn't help me out.. :(
You need to set the post thumbnail dimensions:
http://codex.wordpress.org/Function_Reference/set_post_thumbnail_size
In your theme's functions.php file, add this line:
set_post_thumbnail_size( 250, 250, true );
You will need to rebuild your thumbnails after doing this. Ajax thumbnail rebuild is a great plugin for that.
See the codex link for more explanation.

Wordpress Function Only Apply To Single Page (Post Thumbnail)

I am trying to control my post thumbnail size on two different pages.
I am using
set_post_thumbnail_size( 875, 175 );
To control the size on my index page. And then when they open the post I want the single.php to have the full size image.
Use get_the_post_thumbnail, you would call this in your single.php template and specify the size you want.
You add an image size with add_image_size(); (documentation) and then call on the thumbnail size in your theme with the_post_thumbnail();. You can add as many image sizes as you would like.
So lets create two sizes with
add_image_size( 'home-thumb', 330, 175, true);
add_image_size( 'single-thumb', 875, 300, true );
This will add them and you can call them using using the_post_thumbnail('single-thumb'); since you want the single page to have the full image size you can just use the_post_thumbnail();.
Try this:
if(is_single()) {
set_post_thumbnail_size( 875, 175 );
} else {
set_post_thumbnail_size( other dimensions here );
}

Categories