怎么上传SVG到WordPress

众所周知,WP天生不支持SVG文件上传,尝试上传SVG你会看到如下错误

我们怎么解决呢? 两种方法,一种下载插件如 SVG Support,另一种利用WP提供的钩子upload_mimes

  • 进到Panel或者其他文件编辑器 wp根目录-> 文件管理.
  • 编辑 wp-includes/functions.php文件
function add_file_types_to_uploads($file_types){
  $new_filetypes = array();
  $new_filetypes['svg'] = 'image/svg+xml';
  $file_types = array_merge($file_types, $new_filetypes );
  return $file_types;
}
add_filter('upload_mimes', 'add_file_types_to_uploads');

把上面的代码粘贴到文件最后一行,刷新后台就可以上传了。

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注