admin管理员组文章数量:1313001
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?
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?
Share Improve this question edited Mar 2, 2020 at 21:14 Tom J Nowell♦ 61k7 gold badges79 silver badges148 bronze badges asked Mar 2, 2020 at 18:38 Amy EvansAmy Evans 211 silver badge2 bronze badges 1- 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
Reset to default 5First 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.
本文标签: Restrict Image Uploads to a Certain File Type
版权声明:本文标题:Restrict Image Uploads to a Certain File Type 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741866730a2401950.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论