I'm looking for a way to restrict the size of the media when uploading (a plugin or just a function).

So I found this:

function increase_upload_size_limit( $limit ) {
  return 524288;
add_filter( 'upload_size_limit', 'increase_upload_size_limit' );

And it's working, but the thing is that i'd like to choose a different size restriction for a pdf than for a jpeg.

The thing that would really be perfect is to be able to choose the max size per format. And when uploading a media, it tries compressing it, and if the compression isn't able to compress enough (to be under the max size selected) then there's a message saying that this media can't be uploaded due to its size.

So if it just restrict upload size by format it will be good enough for me.

Thanks a lot!

  • Plugin recommendations are off topic here, so I've removed that from your question. Note that the filter you've used is also used to display the upload limit in the UI, so it can run when no files are being uploaded
    – Tom J Nowell
    Jan 5, 2021 at 10:03
  • @QStudio that restricts the kinds of files you can upload, not the size. The OP wants different upper limits for different file types, e.g. you can't upload a JPEG bigger than 1MB but you can upload a 5MB PDF
    – Tom J Nowell
    Jan 5, 2021 at 10:06
  • Yep - got that too late - perhaps this ticket: wordpress.stackexchange.com/a/133527/7968
    – Q Studio
    Jan 5, 2021 at 10:08


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.