欢迎光临
请一秒记住我们的网址:www.xinfans.com !

WordPress增加上传svg、ico、webp文件权限的方法:

目前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'
赞(18) 加关注
版权声明:本文采用知识共享 署名4.0国际许可协议 [BY-NC-SA] 进行授权
文章名称:WordPress增加上传svg、ico、webp文件权限的方法:
文章链接:https://www.xinfangs.com/959.html
本站资源仅供个人学习交流,请于下载后24小时内删除,不允许用于商业用途,否则法律问题自行承担。

请一秒记住我们的网址:www.xinfans.com !

去投稿去留言

扫码关注公众号

非常感谢,让我们一起创建更加美好的网络世界!

关注公众号

加微信

登录

找回密码

注册