Download an image from a webpage to the default uploads folder

I recently had to do this via a nightly cron script for a social media stream. $parent_id is the ID of the post you want to attach the image to. function uploadRemoteImageAndAttach($image_url, $parent_id){ $image = $image_url; $get = wp_remote_get( $image ); $type = wp_remote_retrieve_header( $get, ‘content-type’ ); if (!$type) return false; $mirror = wp_upload_bits( basename( … Read more

WordPress adding scaled images that don’t exist (1536×1536 and 2048×2048)

I found the culprit! WordPress 5.3 introduced additional image sizes which can be found via /wp-includes/media.php. Updating my function, like so, removed the extra sizes: function remove_default_image_sizes( $sizes) { unset( $sizes[‘large’]); // Added to remove 1024 unset( $sizes[‘thumbnail’]); unset( $sizes[‘medium’]); unset( $sizes[‘medium_large’]); unset( $sizes[‘1536×1536’]); unset( $sizes[‘2048×2048’]); return $sizes; } add_filter(‘intermediate_image_sizes_advanced’, ‘remove_default_image_sizes’);

How to automatically add rounded corners to thumbnails?

Looks like you can hook into the wp_create_thumbnail filter: function wp_create_thumbnail( $file, $max_side, $deprecated = ” ) { if ( !empty( $deprecated ) ) _deprecated_argument( __FUNCTION__, ‘1.2’ ); $thumbpath = image_resize( $file, $max_side, $max_side ); return apply_filters( ‘wp_create_thumbnail’, $thumbpath ); } So just do your manipulation, and return the result to wp_create_thumbnail.

How to delete resized (cropped) image uploads and prevent future resizing?

A majority of the answers covered how to stop creating future default image sizes but this doesnt account for creating any custom sizes in your theme but here is another solution to add to functions.php: function wpse_240765_unset_images( $sizes ){ unset( $sizes[ ‘thumbnail’ ]); unset( $sizes[ ‘medium’ ]); unset( $sizes[ ‘medium_large’ ] ); unset( $sizes[ ‘large’ … Read more

Add an alignment option for images

I agree with david-binda – great question! I’ve run in to this problem on a number of occasions and come up with a solution that works pretty well. While I do like the idea of adding a shortcode to insert the image with classes as suggested by pavlos-bizimis I don’t think it really solves the … Read more

Set default image link target in Gutenberg image block

This was (finally) fixed to Gutenberg (and will be applicable for both the image and the gallery blocks); and will add an option to WordPress options’ database table. this was done in https://github.com/WordPress/gutenberg/pull/25578 and https://github.com/WordPress/gutenberg/pull/25582 It’ll be added to WordPress 5.6 but it’s already available in the Gutenberg plugin. To link the image to the … Read more

Each custom image size in custom upload directory?

Philipp, anything is possible if you set your mind to it. You can solve your issue by extending the WordPress image editor class. Note I’m using WordPress 3.7 – I haven’t checked any of the below code in earlier versions and in the latest 3.8 release. Image Editor basics WordPress has two built in classes … Read more

Custom image size / thumbnail – Crop to aspect ratio even when source image is smaller than set dimensions

This isn’t a really good solution since it’s a newer CSS solution and it’s only working in 78.9% of users browsers, but there are a few polyfills that can overcome that object-fit-images and fitie img { display: block; overflow: hidden; width: 400px; height: 400px; -o-object-fit: cover; object-fit: cover; } Ideally it would be better if … Read more