{"id":45715,"date":"2022-07-08T14:30:14","date_gmt":"2022-07-08T14:30:14","guid":{"rendered":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/?p=45715"},"modified":"2026-10-10T20:56:37","modified_gmt":"2026-10-10T20:56:37","slug":"disable-wordpress-default-image-sizes","status":"publish","type":"post","link":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/disable-wordpress-default-image-sizes\/","title":{"rendered":"Disable WordPress Default Image Sizes"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">For every image you upload, WordPress creates several resized copies. Besides thumbnail, medium and large, it also makes <code>medium_large<\/code> (768px wide), <code>1536x1536<\/code> and <code>2048x2048<\/code>. If your design never uses those, they only fill the uploads folder and slow down every upload.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This snippet disables those WordPress default image sizes for new uploads and leaves thumbnail, medium, large and your theme&#8217;s own sizes alone.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The snippet<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">&lt;?php\n\/**\n * Stop WordPress from generating image sizes you never use.\n *\/\nadd_filter( 'intermediate_image_sizes_advanced', 'dpc_disable_image_sizes' );\n\nfunction dpc_disable_image_sizes( $sizes ) {\n\t\/\/ ===== Config: size names WordPress should not create =====\n\t$disabled = array( 'medium_large', '1536x1536', '2048x2048' );\n\t\/\/ ===== End of config =====\n\n\t$disabled = (array) apply_filters( 'dpc_disabled_image_sizes', $disabled );\n\tforeach ( $disabled as $name ) {\n\t\tunset( $sizes&#91; $name &#93; );\n\t}\n\n\treturn $sizes;\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">How it works<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>When WordPress creates the sub-sizes of an upload, it passes the list of sizes through <code>intermediate_image_sizes_advanced<\/code>. Each key is a size name, so removing a key means that file is never made.<\/li>\n\n\n<li>The same filter is used when WordPress retries missing sizes after a failed upload, so the disabled sizes do not come back later.<\/li>\n\n\n<li>The sizes stay registered. Code that asks for <code>medium_large<\/code> gets the next best file WordPress has, as it does for any missing size.<\/li>\n\n\n<li>The old version used two filters and two functions for the same job, with an unprefixed function name. One list is easier to edit.<\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Add it with Scripts Organizer<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In <a href=\"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/dplugins.com\/downloads\/scripts-organizer\/\">Scripts Organizer<\/a> go to <strong>Code Blocks \u2192 Add New<\/strong> and give the block a name. Set <strong>Trigger location<\/strong> to <strong>Everywhere<\/strong>, tick <strong>PHP<\/strong> under <strong>Script location<\/strong>, paste the code into the PHP editor and publish. Leave <strong>Action\/Hook<\/strong> empty. Uploads happen in wp-admin, the block editor (REST API) and front-end forms, and Everywhere covers all of them.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The same code also works unchanged in a small plugin or an mu-plugin.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Customise it<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Keep one of the sizes: remove its name from <code>$disabled<\/code>. Many themes use <code>1536x1536<\/code> for retina images in <code>srcset<\/code>, so check before you remove it.<\/li>\n\n\n<li>Disable a size added by a theme or plugin: add its name, for example <code>'woocommerce_single'<\/code>.<\/li>\n\n\n<li>Thumbnail, medium and large can also be switched off in <strong>Settings \u2192 Media<\/strong> by setting both their width and height to <code>0<\/code>.<\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Gotchas<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Files that already exist are not deleted. Regenerate the thumbnails with a plugin or <code>wp media regenerate<\/code> if you want to clean up, after you have checked that nothing links to them.<\/li>\n\n\n<li>Images larger than 2560px are still scaled down to a <code>-scaled<\/code> copy. That is controlled by the <code>big_image_size_threshold<\/code> filter, not by this list.<\/li>\n\n\n<li>Fewer sizes also means fewer <code>srcset<\/code> candidates. If large images look soft on some screens, keep <code>1536x1536<\/code>; see <a href=\"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/images-are-not-sharp-enough-when-they-are-scaled-down\/\">Images are not sharp enough when they are scaled down<\/a>.<\/li>\n\n<\/ul>\n\n","protected":false},"excerpt":{"rendered":"<p>Stop WordPress from creating the medium_large, 1536&#215;1536 and 2048&#215;2048 image sizes for every upload, and keep the sizes you use.<\/p>\n","protected":false},"author":5,"featured_media":46856,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"slim_seo":{"title":"Disable WordPress Default Image Sizes - Code DPlugins","description":"Stop WordPress from creating the medium_large, 1536x1536 and 2048x2048 image sizes for every upload, and keep the sizes you use."},"_slim_seo_primary_term_category":0,"_slim_seo_primary_term_post_tag":0,"footnotes":""},"categories":[3],"tags":[59],"dpc_library":[204],"class_list":["post-45715","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-wordpress","tag-image"],"_links":{"self":[{"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/posts\/45715","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/comments?post=45715"}],"version-history":[{"count":1,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/posts\/45715\/revisions"}],"predecessor-version":[{"id":46855,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/posts\/45715\/revisions\/46855"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/media\/46856"}],"wp:attachment":[{"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/media?parent=45715"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/categories?post=45715"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/tags?post=45715"},{"taxonomy":"dpc_library","embeddable":true,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/dpc_library?post=45715"}],"curies":[{"name":"wp","href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/api.w.org\/{rel}","templated":true}]}}