php - 新的 wordpress 版本不支持 SVG
问题描述
我有新的 5.8.1 wordpress,但媒体上传器中的 svg 不再工作了。
我使用这段代码来集成 svgs:
function cc_mime_types($mimes) {
$mimes['svg'] = 'image/svg+xml';
return $mimes;
}
add_filter('upload_mimes', 'cc_mime_types');
为什么它不起作用?
解决方案
您首先需要提及文件类型和扩展名。这是我的代码!
// Wp v4.7.1 and higher
add_filter( 'wp_check_filetype_and_ext', function($data, $file, $filename, $mimes) {
$filetype = wp_check_filetype( $filename, $mimes );
return [
'ext' => $filetype['ext'],
'type' => $filetype['type'],
'proper_filename' => $data['proper_filename']
];
}, 10, 4 );
function cc_mime_types( $mimes ){
$mimes['svg'] = 'image/svg+xml';
return $mimes;
}
add_filter( 'upload_mimes', 'cc_mime_types' );
function fix_svg() {
echo '<style type="text/css">
.attachment-266x266, .thumbnail img {
width: 100% !important;
height: auto !important;
}
</style>';
}
add_action( 'admin_head', 'fix_svg' );
推荐阅读
- django - 如何使用 Django 为现有表创建一对一字段?
- node.js - 为什么我不能在 linux 中更新 npm?
- mysql - mysql中date_trunc的替代品是什么?
- database - TDengine taosdump 工具正确使用指定参数
- vba - 使用 Word VBA 隐藏或取消隐藏当前列表段落后,如何调整下一个单词列表段落的编号?
- python - 如何在 firebase 托管上托管我的 python 功能烧瓶应用程序?
- asp.net - 我想在 ASP.NET Core 5.0 MVC 中通过 jQuery 在 foreach 循环中获取第一次迭代的值
- c# - 在 C# 中抽象出条件收益
- c++ - 推荐的 C++ 包含实践
- c++ - 我不明白如何计算以下 c++ 代码的时间复杂度?