29

When an image is uploaded in WordPress, it is saved in its original size, and also as some resized copies in different sizes. In this way it becomes easy to use different sizes, of the same image, for different purposes. By default, WordPress creates 3 copies in 3 different sizes: 'thumb' 'medium' 'large' The size in pixels for these 3 sizes can be set in ...


15

Create image file in PNG Format having name screenshot.png and save it in themes root folder.The recommended image size is 880x660. Even recommended image size is 880x660 though it will only be shown as 387x290 but the double-sized image allows for high-resolution viewing on HiDPI displays. For more information see this page. If you don’t already have a ...


14

To built on Max Yudin's answer you should use the intermediate_image_sizes_advanced filter, and not image_size_names_choose. Add to functions.php function add_image_insert_override($sizes){ unset( $sizes['thumbnail']); unset( $sizes['medium']); unset( $sizes['large']); return $sizes; } add_filter('intermediate_image_sizes_advanced', '...


10

You need to define your arguments before you pass them to WP_Query, not after. Also, your meta_query should be an array of an array, not just an array This $query = new WP_Query($thumbs); $thumbs = array( 'meta_query' => array('key' => '_thumbnail_id') ); should look like this $thumbs = array( 'meta_query' => array( ...


9

You can turn your snippet into a function that returns the post thumbnail URL of a post: function wpse81577_get_small_thumb_url( $post_id ) { $thumbSmall = wp_get_attachment_image_src( get_post_thumbnail_id( $post_id ), 'small' ); return $thumbSmall['0']; } Usage, supplying the ID of a post: <?php echo wpse81577_get_small_thumb_url( 59 ); ?>


9

You can also filter intermediate_image_sizes with an empty array. add_filter( 'intermediate_image_sizes', '__return_empty_array' );


8

A quick and easy fix for this is to make use of a plugin called Force Regenerate Thumbnails (to which I don't have any affiliation to) Unlike a plugin like Regenerating Thumbnails, Force Regenerate Thumbnails creates all your new custom sizes and delete all redundant/orphaned sizes. Force Regenerate Thumbnails allows you to delete all old images size ...


8

Thumbnails in WordPress can be generated by using wp_generate_attachment_metadata(), this function fires a filter after generating all the thumbnails wp_generate_attachment_metadata and the filter provides $metadata and $attachment_id to the hooked functions. You can hook your custom function to this filter. $metadata : Attachment metadata. What you need ...


7

This should get you started: Loop over all posts and build an array of linked image files Loop over all image attachments & cross check if any of them have been linked to Might need to batch it or boost the timeout & memory limit, depending on the server & number of posts you're working with. $posts = get_posts( array( '...


7

That's easy! If you have SSH access, log in and do the following for each size. I am just showing 150x150 size only. Go to the desired uploads folder via command line. cd /your-site.com/wp-content/uploads Let's find if that size is available. find ./uploads/* -iname '*-150x150.*' -ls If you see some images as the output then delete 'em with find ./...


6

I have just achieved the effect by my own. I will post it here in case others find this thread: jQuery(document).on('click','.thumbnails .zoom', function(){ var photo_fullsize = jQuery(this).find('img').attr('src').replace('-100x132',''); jQuery('.woocommerce-main-image img').attr('src', photo_fullsize); return false; }); ....


6

Figured it out after a lot of trial and error and a lot of var_dumps. $image = wp_get_image_editor($file); if ( ! is_wp_error( $image ) ) { $image->resize( $width, $height, true ); $final_image = $image->save( $file ); } Then i can use the $final_image array to get what i need. It actually saved me a step from what i was doing and seems to ...


6

add_filter('intermediate_image_sizes_advanced', 'filter_image_sizes'); function filter_image_sizes( $sizes) { unset( $sizes['thumbnail']); unset( $sizes['medium']); unset( $sizes['large']); return $sizes; }


6

You can do that because you can add all the attributes you need: the_post_thumbnail( 'large', array( 'title' => get_the_title() ) ); Please read on in the Function Reference of the_post_thumbnail.


6

Don't know why you want to do it when there're update_post_thumbnail_cache() in WordPress and set expire headers on server side. But you can try this in your functions.php: add_filter('wp_get_attachment_image_src', function($img, $id, $size, $icon) { $img[0] = $img[0] . '?v=20160505'; return $img; }, 10, 4);


5

Notes Solution for YouTube and Vimeo. Uses Featured Image or default thumbnail from video provider. If more than one oEmbed exists in the same page, using the Featured Image provoques duplicate "thumbs". Post has to be updated before changes are seen. To do: <iframe> and <img> sizes, other oEmbeds. Sources of Inspiration oEmbed oEmbed, ...


5

As per the Codex entry for the_post_thumbnail(), you can pass an attributes array as a parameter: <?php the_post_thumbnail( $size, $attr ); ?> So you would just need to define the array; here's the Codex example, modified to include the title attribute: $post_thumbnail_attr = array( 'src' => $src, 'class' => "attachment-$size", '...


5

I found the same issue here and the solution from there works. The solution is as simple as pasting this: $content_width = 2000;// Value higher than your new 'large' width in functions.php Explanation copied from there(user Chip Bennett): I believe your issue is that the value set for the global $content_width variable (which is 640px in Boilerplate and ...


5

If you use WP-CLI then that will automatically delete those sizes that you don't need. You would run the following command on your server via SSH. You will need to have WP-CLI installed on the server. wp media regenerate --only-missing You could also use find . -name "*-*x*.*" | xargs rm -f to delete all of the thumbnails from your uploads folder. Make ...


5

I think this code will help you: $src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full', false, '' ); echo '<img src="'.$src[0].'">';


5

Demo Plugin - Fixed Size Here's one suggestion as a demo plugin (PHP 5.4+): <?php /* Plugin Name: Custom Playlist Thumb Size */ namespace WPSE238646\PlaylistThumbSize; add_shortcode( 'playlist', function( $atts = [], $content = '' ) { add_filter( 'wp_get_attachment_image_src', __NAMESPACE__ . '\\src' , 10, 3 ); $out = wp_playlist_shortcode( $...


5

To show a srcset, there must be multiple image sizes of the same aspect ratio. When you set your thumbnail to hard crop without creating any other image sizes you are ensuring that there won't be a srcset. You might find my answer here helpful. Briefly, in your case, adding this line: add_image_size ( 'double-size', 1270, 400, true ); ... will make a ...


4

JavaScript solution As the original answer already work with string replace, but has to get altered for each and every use case, here's a solution using a fast Regex .test() wrapped up in a self invoking function that uses the default method to prevent events (like following links) from happening. This plugin will delete the first occurrence of any 2-4 ...


4

When the first image is a Wordpress image attachment. in 3.6, there is an easier way. function get_first_image_medium_size_url($post_id) { if(!$images = get_attached_images($post_id)) return false; $first_image = current($images); if(!$src = wp_get_attachment_image_src($first_image->ID,'medium')) return false; $medium_url = current($src);...


4

There's not enough info to be sure this answer is definitive but here's an attempt. Firstly make sure the image you are uploading is actually larger than the size you have defined. I see people upload images that are too small and then get this sort of result all the time. Secondly, WP will only make up a Srcset list of image sizes with the same aspect ...


3

Built in Just set the sizes you don't need to 0. This skips the process of creating them. I know, it's not documented, but it works.


3

Pure PHP question, really. global $urlSmall; $urlSmall = $thumbSmall['0']; If you declare the variable with the global keyword when you initialize it it will be available thereafter. You can imprort it, so to speak, with... global $urlSmall; var_dump($urlSmall); You can do the same thing by assigning key/values directly to the $GLOBALS array. $GLOBALS['...


3

Just filter admin_post_thumbnail_html and append your checkbox HTML: add_filter( 'admin_post_thumbnail_html', 'wpse_71501_thumbnail_options' ); function wpse_71501_thumbnail_options( $html ) { return $html . <<<html <p> <label for="big_thumbnail"> <input id="big_thumbnail" name="big_thumbnail" type="checkbox" /> ...


3

Isn't it because you're using $crop as true, as the 4th parameter for the add_image_size() function? This will crop the image and does not actually resize the image.


3

If I remember right you have to unset all the defaults and add the new Size there: <?php function mxdCustomImageSizes($sizes) { unset( $sizes['thumbnail']); unset( $sizes['medium']); unset( $sizes['large']); unset( $sizes['full'] ); $myimgsizes = array( 'full-size' => __( 'Full Size' ) ); if( !empty($sizes) ) ...


Only top voted, non community-wiki answers of a minimum length are eligible