Skip to content

Instantly share code, notes, and snippets.

@czenzel
Created August 1, 2016 07:29
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save czenzel/0f5888cbbfa4a857e56361dd3bc19b39 to your computer and use it in GitHub Desktop.
Save czenzel/0f5888cbbfa4a857e56361dd3bc19b39 to your computer and use it in GitHub Desktop.
Wordpress - Disable Automatic Image Cropping
<?php
/*
Plugin Name: Disable Automatic Image Crop
Author: Wordpress Community
Description: wpse124009 - http://wordpress.stackexchange.com/questions/124009/why-wordpress-automatic-cropping-all-my-images and https://developer.wordpress.org/reference/functions/remove_image_size/
*/
add_action( 'init', 'czc_disable_extra_image_sizes' );
add_filter( 'image_resize_dimensions', 'czc_disable_crop', 10, 6 );
function czc_disable_crop( $enable, $orig_w, $orig_h, $dest_w, $dest_h, $crop )
{
// Instantly disable this filter after the first run
// remove_filter( current_filter(), __FUNCTION__ );
// return image_resize_dimensions( $orig_w, $orig_h, $dest_w, $dest_h, false );
return false;
}
function czc_disable_extra_image_sizes() {
foreach ( get_intermediate_image_sizes() as $size ) {
remove_image_size( $size );
}
}
?>
@ethan-kusters
Copy link

Hi Christopher!
I'd like to disable image cropping site-wide on my Wordpress site. Can you briefly explain how to install/use this plugin?

Copy link

ghost commented Nov 3, 2017

@Feriman22
Copy link

It's working well on my WP Multisite, just put the file into mu-plugins folder.

Thank you!

@gianghl1983
Copy link

Hi,

Thank you for this snippet. Is there anyway to disable for small images (with W,H dimension <1,024px for example)?

Br,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment