最近做几个项目,在添加文章的时候,WordPress支持添加媒体,包括图片、视频、Word和Excel等等各种多媒体文件。如果你想知道WordPress支持上传的所有文件类型,可以在当前主题的functions.php中插入以下php代码,然后打开博客首页,查看网页源代码,即可看到一个完整的支持列表:
1
print_r(wp_get_mime_types());
我们今天要讲的是如何让wordpress只支持上传图片文件,其他文件一概拒绝上传。其实实现方法很简单,我们在当前主题的functions.php中插入以下php代码即可:
1
2
3
4
5
6
7
8
9
10
11
12
13
// Add the filter
add_filter('upload_mimes', 'custom_upload_mimes');
function custom_upload_mimes( $existing_mimes=
array() ) {
$existing_mimes =
array('jpg|jpeg|jpe' => 'image/jpeg',
'gif' => 'image/gif',
'png' => 'image/png',
'bmp' => 'image/bmp',
'tif|tiff' => 'image/tiff',
'ico' => 'image/x-icon');
return $existing_mimes;
}
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报。