admin管理员组文章数量:1023098
I have a few posts that require their thumbnail sizes to be 1000x430. If I register this size and regenerate the thumbnails, it will create this size for all images in the media folder, if I'm not mistaken. If that's the case, that would be way too many 1000x430 images I don't need. Is there a way to only create this thumbnail size for the images I want?
I have a few posts that require their thumbnail sizes to be 1000x430. If I register this size and regenerate the thumbnails, it will create this size for all images in the media folder, if I'm not mistaken. If that's the case, that would be way too many 1000x430 images I don't need. Is there a way to only create this thumbnail size for the images I want?
Share Improve this question asked Apr 22, 2019 at 22:59 DesiDesi 1,2494 gold badges37 silver badges54 bronze badges1 Answer
Reset to default 0Yes, you can choose to regenerate the thumbnails for specific images. You have 2 options.
1- Create a simple plugin
Generating thumbnails is done via the wp_generate_attachment_metadata()
function, which you can use to generate thumbnails manually. To do so, make a simple plugin that loops through a couple of attachment IDs and generates thumbnail for them. Here's what you need:
<?php
/**
* Plugin Name: Generate Thumbnails
* Plugin URI: http://example/
* Description: A plugin to generate some thumbnails.
* Version: 1.0
* Author: Desi
* Author URI: http://example
* Text Domain: desi
*
*/
// Trigger our function once the plugin has been activated
register_activation_hook( __FILE__, 'wpse335041_regenerate_thumbnails' );
function wpse335041_regenerate_thumbnails(){
// This is an array of attachment ids
$attachment_ids = [ 14, 490, 77, 129 ];
// Loop through the ids and generate thumbnail for each
foreach ( $attachment_ids as $id ) {
// Check if the attachment is an image
if( wp_attachment_is_image( $id ) ){
// Get the attachment path
$attachment = get_attached_file( $id );
if( $attachment ) {
// Generate thumbnails and metadata
wp_generate_attachment_metadata( $id, $attachment );
}
}
}
}
All you have to do now is to activate the plugin. If there are lots of images that need regeneration, it might take a while.
2- Use a plugin
There's a well-known plugin in the plugin repository that can be used to regenerate the thumbnails for a single or multiple image. You can download the plugin via the plugin repository here. Notice that I'm not the plugin's author.
I have a few posts that require their thumbnail sizes to be 1000x430. If I register this size and regenerate the thumbnails, it will create this size for all images in the media folder, if I'm not mistaken. If that's the case, that would be way too many 1000x430 images I don't need. Is there a way to only create this thumbnail size for the images I want?
I have a few posts that require their thumbnail sizes to be 1000x430. If I register this size and regenerate the thumbnails, it will create this size for all images in the media folder, if I'm not mistaken. If that's the case, that would be way too many 1000x430 images I don't need. Is there a way to only create this thumbnail size for the images I want?
Share Improve this question asked Apr 22, 2019 at 22:59 DesiDesi 1,2494 gold badges37 silver badges54 bronze badges1 Answer
Reset to default 0Yes, you can choose to regenerate the thumbnails for specific images. You have 2 options.
1- Create a simple plugin
Generating thumbnails is done via the wp_generate_attachment_metadata()
function, which you can use to generate thumbnails manually. To do so, make a simple plugin that loops through a couple of attachment IDs and generates thumbnail for them. Here's what you need:
<?php
/**
* Plugin Name: Generate Thumbnails
* Plugin URI: http://example/
* Description: A plugin to generate some thumbnails.
* Version: 1.0
* Author: Desi
* Author URI: http://example
* Text Domain: desi
*
*/
// Trigger our function once the plugin has been activated
register_activation_hook( __FILE__, 'wpse335041_regenerate_thumbnails' );
function wpse335041_regenerate_thumbnails(){
// This is an array of attachment ids
$attachment_ids = [ 14, 490, 77, 129 ];
// Loop through the ids and generate thumbnail for each
foreach ( $attachment_ids as $id ) {
// Check if the attachment is an image
if( wp_attachment_is_image( $id ) ){
// Get the attachment path
$attachment = get_attached_file( $id );
if( $attachment ) {
// Generate thumbnails and metadata
wp_generate_attachment_metadata( $id, $attachment );
}
}
}
}
All you have to do now is to activate the plugin. If there are lots of images that need regeneration, it might take a while.
2- Use a plugin
There's a well-known plugin in the plugin repository that can be used to regenerate the thumbnails for a single or multiple image. You can download the plugin via the plugin repository here. Notice that I'm not the plugin's author.
本文标签: Create thumbnail size only for a few images
版权声明:本文标题:Create thumbnail size only for a few images? 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745564503a2156367.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论