Create thumbnail size only for a few images?

I have a few posts that require their thumbnail sizes to be 1000x430. If I register this size and regenerate the thumbna

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 badges
Add a comment  | 

1 Answer 1

Reset to default 0

Yes, 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.

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

相关推荐

  • Create thumbnail size only for a few images?

    I have a few posts that require their thumbnail sizes to be 1000x430. If I register this size and regenerate the thumbna

    14小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

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

关注微信