I'm a content manager and want to make sure that all images uploaded by my writers onto WordPress are in JPEG format, rather than PNG as this slows the site down. Is there a way for me to check the nature of the file type as an administrator?
-
Why only Jpegs? Is this because PNGs have larger filesizes? Why not ask how to limit the filesizes of images uploaded? Or how to convert PNG files into JPEG on upload? A well crafted PNG can be much smaller than the equivalent JPEG if done right– Tom J Nowell ♦Commented Mar 2, 2020 at 21:13
1 Answer
First off, PNGs do not necessarily slow your site down anymore than a JPG. It all depends on how the image is saved or optimized and the file size. Anyway.
You have a couple options. Since this site is about coding and we don't support 3rd party plugins I will give you this first.
You can filter the file types the WordPress allows by using upload_mimes. Here is an example of allowing only JPG images.
function wpse_restrict_mimes($mime_types){
$mime_types = array(
'jpg|jpeg' => 'image/jpeg'
);
return $mime_types;
}
add_filter('upload_mimes', 'wpse_restrict_mimes');
Now if someone tries to upload anything other than a JPG they will get a message like this...
This code would go in your theme or better yet Child Theme's functions.php file. Keep in mind it will effect the entire site.
You mentioned being a content manager, if your not comfortable with code their are plugins out there that will do this for you. I would suggest using Google to find a couple, read the reviews and make sure the plugin is up-to-date. Something LIKE THIS looks like it may work.
-
This would have been better as a plugin, put a plugin comment and an opening PHP tag and hey presto it's an entire plugin ready to go. Otherwise the author might need to create a child theme to not lose this if they update their theme, or change it– Tom J Nowell ♦Commented Mar 2, 2020 at 19:09
-
-
That helped me a lot. Thank you. But what if pdf's should be allowed too? And...Anyway to have a file type restriction like this on all other then admin?– LarsCommented Jan 4, 2021 at 16:42