Skip to content

Instantly share code, notes, and snippets.

@chrisdavidmiles
Forked from gmmedia/functions.php
Last active August 30, 2022 06:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisdavidmiles/6fd21201d16f8a7e434b06b903d4706c to your computer and use it in GitHub Desktop.
Save chrisdavidmiles/6fd21201d16f8a7e434b06b903d4706c to your computer and use it in GitHub Desktop.
WordPress Plugin: Remove Unwanted Image Sizes
<?php
/**
* Plugin Name: Remove Unwanted Default Image Sizes
* Plugin URI: https://gist.github.com/chrisdavidmiles/6fd21201d16f8a7e434b06b903d4706c
* Description: This removes three default image sizes that I don't want: medium_large, 1536x1536, and 2048x2048.
* Author: Jochen Gererstorfer
* Author URI: https://bloggerpilot.com/en/disable-wordpress-image-sizes/
* Version: 0.3
*/
if ( ! defined( 'ABSPATH' ) ) die;
// Remove medium_large
add_filter('intermediate_image_sizes', function($sizes) {
return array_diff($sizes, ['medium_large']); // Medium Large (768 x 0)
});
// Remove 1536x1536 and 2048x2048
add_action( 'init', 'cdm_remove_large_image_sizes' );
function cdm_remove_large_image_sizes() {
remove_image_size( '1536x1536' ); // 2 x Medium Large (1536 x 1536)
remove_image_size( '2048x2048' ); // 2 x Large (2048 x 2048)
}
// disable WordPress 5.3 image downscaling feature
add_filter( 'big_image_size_threshold', '__return_false' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment