How to change thumbnail default size?

I have added the following code in my functions.php add_theme_support( 'post-thumbnails' );set_post_thumbna

I have added the following code in my functions.php

add_theme_support( 'post-thumbnails' );  
set_post_thumbnail_size( 150, 150);

My posts display with a thumbnail with the 150x150 dimensions. However, I'd like to change the size. When I change the 150 by 150 in the set_post_thumbnail_size to 200 or any other number, it doesn't actually change the size of my thumbnails. I tried going into media settings and change the size there. In the media settings I can shrink the size, but if I try to change it to 200 or 300 it doesn't actually have any impact.

Any idea how I can modify it?

I have added the following code in my functions.php

add_theme_support( 'post-thumbnails' );  
set_post_thumbnail_size( 150, 150);

My posts display with a thumbnail with the 150x150 dimensions. However, I'd like to change the size. When I change the 150 by 150 in the set_post_thumbnail_size to 200 or any other number, it doesn't actually change the size of my thumbnails. I tried going into media settings and change the size there. In the media settings I can shrink the size, but if I try to change it to 200 or 300 it doesn't actually have any impact.

Any idea how I can modify it?

Share Improve this question edited Mar 28, 2016 at 20:52 birgire 68.1k7 gold badges120 silver badges252 bronze badges asked Mar 28, 2016 at 20:47 user91325user91325 11 silver badge5 bronze badges 4
  • Hmm.. maybe you could look into add_image_size() – Stephen Commented Mar 28, 2016 at 21:20
  • you need define in size measure, what do you mean "it doesn't actually change the size" ? – Jevuska Commented Mar 29, 2016 at 0:14
  • 2 i think that you have to regenerate your thumbnails with this kind of plugins: Regenerate Thumbnails or/and Force Regenerate Thumbnails. – LoicTheAztec Commented Mar 29, 2016 at 3:05
  • Your code seems to be fine. Something wrong in your call I guess. Please take a look at here nerodev/creating-post-thumbnails-in-wordpress – user2584538 Commented Oct 25, 2018 at 5:33
Add a comment  | 

2 Answers 2

Reset to default 1

The code you are using is correct. The problem is that you are looking at thumbnails that have already been created. As @Loius mentioned you will need to use Regenerate Thumbnails to see the effect. Why core has not implemented this is beyond me.

Define your own image sizes

If you need your post thumbnail 50px by 50px without cropping the image as well without distorting it. Here is the solution. These all definitions should define in functions.php file.

set_post_thumbnail_size( 50, 50 ); // 50 pixels wide by 50 pixels tall, resize mode

As well as you can crop the image as you want. Here is an example for cropping.

set_post_thumbnail_size( 50, 50, array( 'top', 'left') ); // 50 pixels wide by 50 pixels tall, crop from the top left corner

In the array have pass the where to crop. This will crop the image starting from top left corner. If you need to crop the image from the center, just pass array( 'center', 'center' ) . This will crop the image from the center.

Not only these. You can define your own thumbnail name and define the sizes. Assume I need to create a thumbnail image for books category. Therefore I need an image 200px width and height should be auto . Lets see how to do this.

add_image_size( 'books', 200, 9999 ); //200 pixels wide (and unlimited height)

This will resize the book category image to 200px width and auto height.

You can call this image

<?php the_post_thumbnail( 'books' ); ?>

In a proper way you can call this image,

<?php
if(has_post_thumbnail( 'books' )) {
the_post_thumbnail( 'books' );
}
?>

This will load the image where you define the code and it will be 200px wide and height is relative to the width.

Assume you’re wanting to add this Featured Images for books and all posts except other all custom post types. How to do this. See the code below. It’ll enable the Featured Image for all the posts and custom post type called books only.

add_theme_support( 'post-thumbnails', array( 'post', 'books' ) );

Source from nerodev

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745183477a4615527.html

相关推荐

  • How to change thumbnail default size?

    I have added the following code in my functions.php add_theme_support( 'post-thumbnails' );set_post_thumbna

    5小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信