Create thumbnail for featured images only
-
Hello.
I believe everyone here likes to save space on hosting.
To reduce the amount of unnecessary images that take up space, I’m looking for a way to create the thumbails only for the images featured in the posts.
I found in this guide a part of the solution:
https://www.gavsblog.com/blog/regenerate-wordpress-media-image-sizes-programmaticallyrequire_once(ABSPATH . 'wp-admin/includes/image.php'); // Put the function in a class to make it more extendable class GB_regen_media { public function gb_regenerate($imageId) { $imagePath = wp_get_original_image_path($imageId); if ($imagePath && file_exists($imagePath)) { wp_generate_attachment_metadata($imageId, $imagePath); } } } // Add a load function function gb_regen_load() { // Instantiate the class $gb_regen_media = new GB_regen_media(); // Set the image Id $imageId = 1; // You can get the image Id from the url of the media screen $gb_regen_media- >gb_regenerate($imageId); } // Load after WordPress has finished loading add_action('init', 'gb_regen_load');
However, it creates the image using the sizes defined in the theme.
And as I want to prevent copies from being created with each new image uploaded,
I turned off automatic creation by setting everything to “0”.Researching the function used in the above tip:
wp_generate_attachment_metadataI saw that it generates the copies based on the dimensions defined in the theme:
https://www.ads-software.com/support/article/settings-media-screen/But as I explained above, I disabled creation there, to avoid unnecessary images.
Can anyone give me a suggestion to create this thumbnail so that I set the size myself in the function?
because as I said, it is not possible to use the theme size as it is disabled.
Grateful.
- The topic ‘Create thumbnail for featured images only’ is closed to new replies.