目前WordPress后台支持的图片格式都是非常常用的,但随着时代的变迁,现在很多站点需要的格式也越来越多,尤其是webp和svg格式的图片。
不过现在好多的主题没有开启此类图片的上传权限,今天就来教大家简单的开启权限吧
1.直接把代码丢到 functions.php 里保存即可。
复制复制复制复制
复制
- add_filter('upload_mimes', 'tbi_upload_mimes');
- function tbi_upload_mimes($mimes = array()) {
- $mimes['svg'] = 'image/svg+xml';
- $mimes['ico'] = 'image/x-icon';
- $mimes['webp'] = 'image/webp';
- return $mimes;
- }
2.一些WordPress用户的部分主题在上传svg、ico、webp文件时出现“由于安全原因,这个文件类型不受支持上传”的提示,意思是这类图片格式不允许上传,解决方法如下 :
在网站根目录找到 wp-config.php 文件,添加以下代码:
复制复制复制
复制
- define('ALLOW_UNFILTERED_UPLOADS', true);
好了,完工。
如果你还想添加其它类型附件,可以参看下面 MIME 类型添加;
复制复制
复制
- $mimes['jpg|jpeg|jpe'] = 'image/jpeg'
- $mimes['gif'] = 'image/gif'
- $mimes['png'] = 'image/png'
- $mimes['bmp'] = 'image/bmp'
- $mimes['tiff|tif'] = 'image/tiff'
- $mimes['ico'] = 'image/x-icon'
- $mimes['asf|asx'] = 'video/x-ms-asf'
- $mimes['wmv'] = 'video/x-ms-wmv'
- $mimes['wmx'] = 'video/x-ms-wmx'
- $mimes['wm'] = 'video/x-ms-wm'
- $mimes['avi'] = 'video/avi'
- $mimes['divx'] = 'video/divx'
- $mimes['flv'] = 'video/x-flv'
- $mimes['mov|qt'] = 'video/quicktime'
- $mimes['mpeg|mpg|mpe'] = 'video/mpeg'
- $mimes['mp4|m4v'] = 'video/mp4'
- $mimes['ogv'] = 'video/ogg'
- $mimes['webm'] = 'video/webm'
- $mimes['mkv'] = 'video/x-matroska'
- $mimes['3gp|3gpp'] = 'video/3gpp'
- $mimes['3g2|3gp2'] = 'video/3gpp2'
- $mimes['txt|asc|c|cc|h|srt'] = 'text/plain'
- $mimes['csv'] = 'text/csv'
- $mimes['tsv'] = 'text/tab-separated-values'
- $mimes['ics'] = 'text/calendar'
- $mimes['rtx'] = 'text/richtext'
- $mimes['css'] = 'text/css'
- $mimes['htm|html'] = 'text/html'
- $mimes['vtt'] = 'text/vtt'
- $mimes['dfxp'] = 'application/ttaf+xml'
- $mimes['mp3|m4a|m4b'] = 'audio/mpeg'
- $mimes['aac'] = 'audio/aac'
- $mimes['ra|ram'] = 'audio/x-realaudio'
- $mimes['wav'] = 'audio/wav'
- $mimes['ogg|oga'] = 'audio/ogg'
- $mimes['flac'] = 'audio/flac'
- $mimes['mid|midi'] = 'audio/midi'
- $mimes['wma'] = 'audio/x-ms-wma'
- $mimes['wax'] = 'audio/x-ms-wax'
- $mimes['mka'] = 'audio/x-matroska'
- $mimes['rtf'] = 'application/rtf'
- $mimes['js'] = 'application/javascript'
- $mimes['pdf'] = 'application/pdf'
- $mimes['class'] = 'application/java'
- $mimes['tar'] = 'application/x-tar'
- $mimes['zip'] = 'application/zip'
- $mimes['gz|gzip'] = 'application/x-gzip'
- $mimes['rar'] = 'application/rar'
- $mimes['7z'] = 'application/x-7z-compressed'
- $mimes['psd'] = 'application/octet-stream'
- $mimes['xcf'] = 'application/octet-stream'
- $mimes['doc'] = 'application/msword'
- $mimes['pot|pps|ppt'] = 'application/vnd.ms-powerpoint'
- $mimes['wri'] = 'application/vnd.ms-write'
- $mimes['xla|xls|xlt|xlw'] = 'application/vnd.ms-excel'
- $mimes['mdb'] = 'application/vnd.ms-access'
- $mimes['mpp'] = 'application/vnd.ms-project'
- $mimes['docx'] = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
- $mimes['docm'] = 'application/vnd.ms-word.document.macroEnabled.12'
- $mimes['dotx'] = 'application/vnd.openxmlformats-officedocument.wordprocessingml.template'
- $mimes['dotm'] = 'application/vnd.ms-word.template.macroEnabled.12'
- $mimes['xlsx'] = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
- $mimes['xlsm'] = 'application/vnd.ms-excel.sheet.macroEnabled.12'
- $mimes['xlsb'] = 'application/vnd.ms-excel.sheet.binary.macroEnabled.12'
- $mimes['xltx'] = 'application/vnd.openxmlformats-officedocument.spreadsheetml.template'
- $mimes['xltm'] = 'application/vnd.ms-excel.template.macroEnabled.12'
- $mimes['xlam'] = 'application/vnd.ms-excel.addin.macroEnabled.12'
- $mimes['pptx'] = 'application/vnd.openxmlformats-officedocument.presentationml.presentation'
- $mimes['pptm'] = 'application/vnd.ms-powerpoint.presentation.macroEnabled.12'
- $mimes['ppsx'] = 'application/vnd.openxmlformats-officedocument.presentationml.slideshow'
- $mimes['ppsm'] = 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12'
- $mimes['potx'] = 'application/vnd.openxmlformats-officedocument.presentationml.template'
- $mimes['potm'] = 'application/vnd.ms-powerpoint.template.macroEnabled.12'
- $mimes['ppam'] = 'application/vnd.ms-powerpoint.addin.macroEnabled.12'
- $mimes['sldx'] = 'application/vnd.openxmlformats-officedocument.presentationml.slide'
- $mimes['sldm'] = 'application/vnd.ms-powerpoint.slide.macroEnabled.12'
- $mimes['onetoc|onetoc2|onetmp|onepkg'] = 'application/onenote'
- $mimes['oxps'] = 'application/oxps'
- $mimes['xps'] = 'application/vnd.ms-xpsdocument'
- $mimes['odt'] = 'application/vnd.oasis.opendocument.text'
- $mimes['odp'] = 'application/vnd.oasis.opendocument.presentation'
- $mimes['ods'] = 'application/vnd.oasis.opendocument.spreadsheet'
- $mimes['odg'] = 'application/vnd.oasis.opendocument.graphics'
- $mimes['odc'] = 'application/vnd.oasis.opendocument.chart'
- $mimes['odb'] = 'application/vnd.oasis.opendocument.database'
- $mimes['odf'] = 'application/vnd.oasis.opendocument.formula'
- $mimes['wp|wpd'] = 'application/wordperfect'
- $mimes['key'] = 'application/vnd.apple.keynote'
- $mimes['numbers'] = 'application/vnd.apple.numbers'
- $mimes['pages'] = 'application/vnd.apple.pages'
点击阅读余下全文