admin管理员组文章数量:1414628
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 |2 Answers
Reset to default 1The code you are using is correct. The problem is that you are looking at thumbnail
s 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
本文标签: How to change thumbnail default size
版权声明:本文标题:How to change thumbnail default size? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745183477a2646574.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
add_image_size()
– Stephen Commented Mar 28, 2016 at 21:20