Performance PHP Beginner

Stop Generating Preview Images for PDFs

Stop WordPress turning the first page of every uploaded PDF into a set of preview images, which saves upload time and disk space.

Tested on WordPress 7.1 PHP 8.3 No plugin needed Updated
functions.php 1 lines
add_filter( 'fallback_intermediate_image_sizes', '__return_empty_array' );

Where to add this

Recommended A code snippets plugin Survives theme changes and is easy to switch off.
Child theme At the end of your child theme's functions.php file.
Must-use plugin As a .php file in wp-content/mu-plugins, starting with <?php.

Always add PHP to a staging site first, or have FTP or file manager access ready, so you can undo it if something goes wrong.

When you upload a PDF, WordPress renders its first page into several image sizes so the Media Library can show a thumbnail. On sites that upload many PDFs, that’s slow uploads and hundreds of extra files nobody looks at.

How it works

For non-image uploads like PDFs, WordPress uses the fallback_intermediate_image_sizes filter to decide which preview sizes to create. Returning an empty list skips the previews entirely. The PDF itself uploads normally.

Things to watch

  • PDFs will show a generic document icon in the Media Library instead of a preview.
  • Existing preview images aren’t deleted. Remove them with a media cleanup plugin if you need the space back.

How to test it

Upload a PDF, then check the uploads folder for the month: you should see only the PDF, with no -pdf.jpg files.

This website uses cookies to enhance your browsing experience and ensure the site functions properly. By continuing to use this site, you acknowledge and accept our use of cookies.

Accept All Accept Required Only