开发者

Wordpress theme: force creation of newly created thumbnail size

I just added a new Wordpress thumbnail size using add_image_size call, but now all the photos I already uploaded are not of the correct size. If I request them, all I get is the original image with width and height attributes correctly se开发者_如何学JAVAt.

How can I force the creation of that thumb, saving the data to the database as well, given an attachment ID?

Please note I want to do a simple admin operation or execute code from a theme file.


I don't know if there's an operation to do this from the admin, but I can execute this code from a theme file:

require(ABSPATH.'wp-admin/includes/image.php');
$file = str_replace('http://www.example.com/', ABSPATH, $attachment->guid);
wp_update_attachment_metadata( $attachment->ID,
    wp_generate_attachment_metadata( $attachment->ID, $file ) );

that recreates all of the thumb sizes at once (don't know if the already created ones are done as well, but it's a one time code execution).

You must replace "www.example.com" with your URL and $attachment with an actual attachment post structure, retrieved with get_post or similar.


This is bug #13947. Instead of the_post_thumbnail() use this code in your theme until the bug is fixed:

the_post_thumbnail(
    array ( 150, 150 ), // size
    array ( 'class' => 'attachment-post-thumbnail' )
);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜