Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wordpress&;SVG_Wordpress_Svg - Fatal编程技术网

Wordpress&;SVG

Wordpress&;SVG,wordpress,svg,Wordpress,Svg,有人知道如何让wordpress允许使用通过主题定制器面板上传的SVG文件吗 在theme functions.php文件中添加了以下内容,该文件允许上传SVG(尽管没有预览或特色图像) 但是,这仍然不允许我从文件系统上载或选择SVG,也不允许拖放SVG。您可以通过将其添加到当前的themes functions.php文件中来克服安全警告 add_filter('upload_mimes', 'custom_upload_mimes'); function custom_upload_mim

有人知道如何让wordpress允许使用通过主题定制器面板上传的SVG文件吗

在theme functions.php文件中添加了以下内容,该文件允许上传SVG(尽管没有预览或特色图像)


但是,这仍然不允许我从文件系统上载或选择SVG,也不允许拖放SVG。

您可以通过将其添加到当前的themes functions.php文件中来克服安全警告

add_filter('upload_mimes', 'custom_upload_mimes');

function custom_upload_mimes ( $existing_mimes=array() ) {
    // add the file extension to the array
    $existing_mimes['svg'] = 'mime/type';
        // call the modified list of extensions
    return $existing_mimes;
}

然后您应该能够上传扩展名为.svg的文件,使用以下代码在Wordpress中支持svg。它将导入和导出.svg媒体文件

function theme_name_mime_types($mimes) { $mimes['svg'] = 'image/svg+xml'; return $mimes; } add_filter('upload_mimes', 'theme_name_mime_types'); add_filter('mime_types', 'theme_name_mime_types'); 函数主题\名称\ mime\类型($mimes){ $mimes['svg']='image/svg+xml'; 返回$mimes; } 添加过滤器(“上传mime”,“主题名称mime类型”); 添加过滤器(“mime类型”、“主题名称”mime类型); 更新(Wordpres 5+)

确保每个SVG文件都以以下内容开头:

<?xml version="1.0" encoding="utf-8"?>

如果您尝试通过媒体上传器简单地将SVG上传到WordPress,您可能会遇到一些问题

要么它给了您一个错误,不允许您上传文件,要么它允许您上传.svg文件,但不显示它。不管是哪种方式,这里有两个简单的步骤可以轻松地在WordPress中启用SVG图像

注意:您需要能够编辑主题(或子主题)的
functions.php
文件和根
.htaccess
文件,才能使其正常工作

将SVG MIME类型添加到
functions.php
您应该用自己的名称空间替换
wpcontent\uu
。此函数只需将SVG和SVGZ(压缩的SVG)添加到WordPress中允许的上载文件类型中,并挂接到upload_mimes()WordPress函数中

将SVG Mime类型添加到.htaccess 因此,打开根
.htaccess
文件,在行
#End WordPress
后添加以下内容

# Add SVG Mime Types
AddType image/svg+xml svg
AddType image/svg+xml svgz       
保存文件,您就完成了!您现在可以从Illustrator或Inkscape保存SVG,并在WordPress站点上使用它们


Source

注意到,如果使用“为屏幕保存”,文件将不会上载,但“另存为…”有效(illustrator)

这对性能有何影响?这似乎是基于一个类似的答案,该方法可能会更慢。@我没有注意到我车上的速度限制site@Motivated没有做任何特殊的测试。加载大型SVG时,没有明显的速度减慢files@Motivated使用
对象
标记加载一些大型SVG文件,看看您是否对渲染性能感到满意
function wpcontent_svg_mime_type( $mimes = array() ) {
  $mimes['svg']  = 'image/svg+xml';
  $mimes['svgz'] = 'image/svg+xml';
  return $mimes;
}
add_filter( 'upload_mimes', 'wpcontent_svg_mime_type' );   
# Add SVG Mime Types
AddType image/svg+xml svg
AddType image/svg+xml svgz