{"id":31842,"date":"2024-11-25T16:06:44","date_gmt":"2024-11-25T08:06:44","guid":{"rendered":"https:\/\/fwq.ai\/blog\/31842\/"},"modified":"2024-11-25T16:06:44","modified_gmt":"2024-11-25T08:06:44","slug":"%e5%a6%82%e4%bd%95%e8%ae%a9wordpress%e6%94%af%e6%8c%81%e4%b8%8a%e4%bc%a0svg%e6%a0%bc%e5%bc%8f%e5%9b%be%e7%89%87%e5%b9%b6%e6%98%be%e7%a4%ba%e5%9c%a8%e5%aa%92%e4%bd%93%e5%ba%93%e4%b8%ad","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/31842\/","title":{"rendered":"\u5982\u4f55\u8ba9WordPress\u652f\u6301\u4e0a\u4f20SVG\u683c\u5f0f\u56fe\u7247\u5e76\u663e\u793a\u5728\u5a92\u4f53\u5e93\u4e2d"},"content":{"rendered":"<p>\u4e0b\u9762\u7531\/&#8221; target=&#8221;_blank&#8221;&gt;<strong>wordpress\u6559\u7a0b<\/strong>\u680f\u76ee\u7ed9\u5927\u5bb6\u4ecb\u7ecd\u8ba9wordpress\u652f\u6301\u4e0a\u4f20svg\u683c\u5f0f\u56fe\u7247\u5e76\u663e\u793a\u5728\u5a92\u4f53\u5e93\u4e2d\u7684\u65b9\u6cd5\uff0c\u5e0c\u671b\u5bf9\u9700\u8981\u7684\u670b\u53cb\u6709\u6240\u5e2e\u52a9\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/000\/020\/5fd065f5798ee717.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u8ba9WordPress\u652f\u6301\u4e0a\u4f20SVG\u683c\u5f0f\u56fe\u7247\u5e76\u663e\u793a\u5728\u5a92\u4f53\u5e93\u4e2d\u63d2\u56fe\" alt=\"\u5982\u4f55\u8ba9WordPress\u652f\u6301\u4e0a\u4f20SVG\u683c\u5f0f\u56fe\u7247\u5e76\u663e\u793a\u5728\u5a92\u4f53\u5e93\u4e2d\u63d2\u56fe\" \/><\/p>\n<p>\u56e0SVG\u683c\u5f0f\u56fe\u7247\u7279\u6027\uff0c\u53ef\u80fd\u4f1a\u88ab\u63d2\u5165\u6076\u610f\u4ee3\u7801\uff0c\u7f51\u7ad9\u5bb9\u6613\u88ab\u653b\u51fb\uff0c\u6240\u4ee5\u51fa\u4e8e\u5b89\u5168\u8003\u8651WordPress\u9ed8\u8ba4\u4e0d\u652f\u6301SVG\u683c\u5f0f\u56fe\u7247\u4e0a\u4f20\uff0c\u53e6\u5916\u4e0d\u50cf\u7f51\u4e0a\u8bf4SVG\u683c\u5f0f\u56fe\u7247\u6709\u90a3\u4e48\u9ad8\u7684\u5e94\u7528\u4ef7\u503c\uff0c\u9664\u4e86\u4e00\u4e9b\u7f51\u9875\u4e0a\u7684\u5c0f\u56fe\u6807\u53ef\u4ee5\u4f7f\u7528SVG\u56fe\u7247\u5916\uff0c\u6b63\u5e38\u7684\u5f69\u8272\u56fe\u7247\uff0c\u5982\u679c\u4f7f\u7528SVG\u683c\u5f0f\u6beb\u65e0\u4f18\u52bf\u53ef\u8a00\u3002\u4e0d\u8fc7\u6709\u65f6\u8fd8\u786e\u5b9e\u9700\u8981\u8fd9\u4e2aSVG\u56fe\u7247\u6bd4\u5982\u6211\u4e3b\u9898\u7684LOGO\u56fe\u7247\uff0c\u5982\u679c\u4f7f\u7528PNG\u56fe\u7247\u5728\u624b\u673a\u4e0a\u4e0d\u662f\u5f88\u6e05\u6670\uff0c\u91c7\u7528SVG\u683c\u5f0f\u5219\u65e0\u6b64\u95ee\u9898\u3002<\/p>\n<p>\u5982\u4f55\u8ba9WordPress\u652f\u6301\u4e0a\u4f20SVG\u683c\u5f0f\u56fe\u7247\uff1f<\/p>\n<p>\u53ef\u4ee5\u5c06\u4e0b\u4ee3\u7801\u6dfb\u52a0\u5f53\u524d\u4e3b\u9898\u51fd\u6570\u6a21\u677ffunctions.php\u4e2d\uff1a<\/p>\n<p>\u8ba9WordPress\u652f\u6301\u4e0a\u4f20SVG\uff0c\u5e76\u53ea\u7ba1\u7406\u5458\u6709\u6b64\u6743\u9650<\/p>\n<pre>\/\/&nbsp;\u53ea\u5141\u8bb8\u7ba1\u7406\u5458\u4e0a\u4f20SVG\u56fe\u7247\nif&nbsp;(current_user_can(&nbsp;'manage_options'&nbsp;))&nbsp;{\nadd_filter('upload_mimes',&nbsp;function&nbsp;($mimes)&nbsp;{\n$mimes['svg']&nbsp;=&nbsp;'image\/svg+xml';\nreturn&nbsp;$mimes;\n});\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5a92\u4f53\u5e93\u5217\u8868\u6a21\u5f0f\u663e\u793aSVG\u56fe\u7247<\/p>\n<pre>\/\/&nbsp;\u5a92\u4f53\u5e93\u5217\u8868\u6a21\u5f0f\u663e\u793aSVG\u56fe\u7247\nadd_action('admin_head',&nbsp;function&nbsp;()&nbsp;{\necho&nbsp;\"&lt;style&gt;table.media .column-title .media-icon img[src*=&#039;.svg&#039;]{width: 100%;height: auto;}.components-responsive-wrapper__content[src*=&#039;.svg&#039;] {position: relative;}&lt;\/style&gt;\";\n});<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u7f51\u4e0a\u6709\u5f88\u591a\u4ee5\u4e0a\u7c7b\u4f3c\u7684\u4ee3\u7801\uff0c\u4f46\u90fd\u4e0d\u652f\u6301\u5a92\u4f53\u5e93\u7f51\u683c\u6a21\u5f0f\u663e\u793aSVG\u56fe\u7247\uff0c\u4e0b\u9762\u7684\u4ee3\u7801\u53ef\u4ee5\u5b9e\u73b0\uff1a<\/p>\n<pre>\/\/&nbsp;\u5a92\u4f53\u5e93\u7f51\u683c\u6a21\u5f0f\u663e\u793aSVG\u56fe\u7247\nfunction&nbsp;zm_display_svg_media($response,&nbsp;$attachment,&nbsp;$meta){\nif($response['type']&nbsp;===&nbsp;'image'&nbsp;&amp;amp;&amp;amp;&nbsp;$response['subtype']&nbsp;===&nbsp;'svg+xml'&nbsp;&amp;amp;&amp;amp;&nbsp;class_exists('SimpleXMLElement')){\ntry&nbsp;{\n$path&nbsp;=&nbsp;get_attached_file($attachment-&amp;gt;ID);\nif(@file_exists($path)){\n$svg&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;new&nbsp;SimpleXMLElement(@file_get_contents($path));\n$src&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;$response['url'];\n$width&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;(int)&nbsp;$svg['width'];\n$height&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;(int)&nbsp;$svg['height'];\n$response['image']&nbsp;&nbsp;=&nbsp;compact(&nbsp;'src',&nbsp;'width',&nbsp;'height'&nbsp;);\n$response['thumb']&nbsp;&nbsp;=&nbsp;compact(&nbsp;'src',&nbsp;'width',&nbsp;'height'&nbsp;);\n&nbsp;\n$response['sizes']['full']&nbsp;=&nbsp;array(\n'height'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&amp;gt;&nbsp;$height,\n'width'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&amp;gt;&nbsp;$width,\n'url'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&amp;gt;&nbsp;$src,\n'orientation'&nbsp;&nbsp;&nbsp;=&amp;gt;&nbsp;$height&nbsp;&amp;gt;&nbsp;$width&nbsp;?&nbsp;'portrait'&nbsp;:&nbsp;'landscape',\n);\n}\n}\ncatch(Exception&nbsp;$e){}\n}\nreturn&nbsp;$response;\n}\nadd_filter('wp_prepare_attachment_for_js',&nbsp;'zm_display_svg_media',&nbsp;10,&nbsp;3);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u53e6\u4e00\u4e2a\u76f8\u5bf9\u4ee3\u7801\u8f83\u5c11\u7684\u652f\u6301\u5a92\u4f53\u5e93\u7f51\u683c\u6a21\u5f0f\u663e\u793aSVG\u56fe\u7247\u4ee3\u7801\uff0c\u4e0d\u8fc7\u5982\u679c\u5f00\u542f\u8c03\u8bd5\u6a21\u5f0f\u4f1a\u6709\u9519\u8bef\u63d0\u793a\uff0c\u4f46\u4e0d\u5f71\u54cd\u4f7f\u7528\u3002<\/p>\n<pre>\/\/&nbsp;\u5a92\u4f53\u5e93\u7f51\u683c\u6a21\u5f0f\u663e\u793aSVG\u56fe\u7247\nfunction&nbsp;zm_svg_metadata($data,&nbsp;$post_id)&nbsp;{\n$data&nbsp;=&nbsp;array(\n'sizes'&nbsp;=&amp;gt;&nbsp;array(\n'large'&nbsp;=&amp;gt;&nbsp;array(\n'file'&nbsp;=&amp;gt;&nbsp;pathinfo(wp_get_attachment_url($post_id),&nbsp;PATHINFO_BASENAME)\n)\n)\n);\nreturn&nbsp;$data;\n}\nadd_filter('wp_get_attachment_metadata',&nbsp;'zm_svg_metadata',&nbsp;10,&nbsp;2);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u81f3\u4e8e\u52a0\u8fd9\u4e2a\u529f\u80fd\u7528\u4e8e\u4ec0\u4e48\uff0c\u90a3\u8981\u770b\u4f60\u7528\u7684\u4e3b\u9898\u662f\u5426\u6709\u8fd9\u4e2a\u529f\u80fd\u9700\u8981\u4e86\uff0c\u76f4\u63a5FTP\u4e0a\u4f20\u540e\u83b7\u53d6\u94fe\u63a5\u4e5f\u4e00\u6837\u5728\u7f51\u9875\u4e2d\u4f7f\u7528\u3002<\/p>\n<p>\u5acc\u6298\u817e\u4ee3\u7801\u9ebb\u70e6\uff0c\u53ef\u4ee5\u4f7f\u7528\u4e0b\u9762\u7684\u76f8\u5173\u63d2\u4ef6\uff1a<\/p>\n<pre>SVG&nbsp;Support\nEnable&nbsp;SVG\nSafe&nbsp;SVG\uff08\u636e\u8bf4\u8be5\u63d2\u4ef6\u53ef\u4ee5\u68c0\u6d4b\u5e76\u53bb\u9664SVG\u4e2d\u7684\u6076\u610f\u4ee3\u7801\uff0c\u4e0e250+110\u6709\u7684\u4e00\u62fc\uff09\nWP&nbsp;SVG&nbsp;images\nEasy&nbsp;SVG&nbsp;Support\nEnable&nbsp;SVG&nbsp;Uploads\n......<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u8ba9WordPress\u652f\u6301\u4e0a\u4f20SVG\u683c\u5f0f\u56fe\u7247\u5e76\u663e\u793a\u5728\u5a92\u4f53\u5e93\u4e2d\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e0b\u9762\u7531\/&#8221; target=&#8221;_blank&#8221;&gt;wordpress\u6559\u7a0b\u680f\u76ee\u7ed9\u5927\u5bb6\u4ecb\u7ecd\u8ba9wordpress\u652f\u6301\u4e0a\u4f20svg\u683c\u5f0f\u56fe\u7247\u5e76\u663e\u793a\u5728\u5a92\u4f53\u5e93\u4e2d\u7684\u65b9\u6cd5\uff0c\u5e0c\u671b\u5bf9\u9700\u8981\u7684\u670b\u53cb\u6709\u6240\u5e2e\u52a9\uff01 \u56e0SVG\u683c\u5f0f\u56fe\u7247\u7279\u6027\uff0c\u53ef\u80fd\u4f1a\u88ab\u63d2\u5165\u6076\u610f\u4ee3\u7801\uff0c\u7f51\u7ad9\u5bb9\u6613\u88ab\u653b\u51fb\uff0c\u6240\u4ee5\u51fa\u4e8e\u5b89\u5168\u8003\u8651WordPress\u9ed8\u8ba4\u4e0d\u652f\u6301SVG\u683c\u5f0f\u56fe\u7247\u4e0a\u4f20\uff0c\u53e6\u5916\u4e0d\u50cf\u7f51\u4e0a\u8bf4SVG\u683c\u5f0f\u56fe\u7247\u6709\u90a3\u4e48\u9ad8\u7684\u5e94\u7528\u4ef7\u503c\uff0c\u9664\u4e86\u4e00\u4e9b\u7f51\u9875\u4e0a\u7684\u5c0f\u56fe\u6807\u53ef\u4ee5\u4f7f\u7528SVG\u56fe\u7247\u5916\uff0c\u6b63\u5e38\u7684\u5f69\u8272\u56fe\u7247\uff0c\u5982\u679c\u4f7f\u7528SVG\u683c\u5f0f\u6beb\u65e0\u4f18\u52bf\u53ef\u8a00\u3002\u4e0d\u8fc7\u6709\u65f6\u8fd8\u786e\u5b9e\u9700\u8981\u8fd9\u4e2aSVG\u56fe\u7247\u6bd4\u5982\u6211\u4e3b\u9898\u7684LOGO\u56fe\u7247\uff0c\u5982\u679c\u4f7f\u7528PNG\u56fe\u7247\u5728\u624b\u673a\u4e0a\u4e0d\u662f\u5f88\u6e05\u6670\uff0c\u91c7\u7528SVG\u683c\u5f0f\u5219\u65e0\u6b64\u95ee\u9898\u3002 \u5982\u4f55\u8ba9WordPress\u652f\u6301\u4e0a\u4f20SVG\u683c\u5f0f\u56fe\u7247\uff1f \u53ef\u4ee5\u5c06\u4e0b\u4ee3\u7801\u6dfb\u52a0\u5f53\u524d\u4e3b\u9898\u51fd\u6570\u6a21\u677ffunctions.php\u4e2d\uff1a \u8ba9WordPress\u652f\u6301\u4e0a\u4f20SVG\uff0c\u5e76\u53ea\u7ba1\u7406\u5458\u6709\u6b64\u6743\u9650 \/\/&nbsp;\u53ea\u5141\u8bb8\u7ba1\u7406\u5458\u4e0a\u4f20SVG\u56fe\u7247 if&nbsp;(current_user_can(&nbsp;&#8216;manage_options&#8217;&nbsp;))&nbsp;{ add_filter(&#8216;upload_mimes&#8217;,&nbsp;function&nbsp;($mimes)&nbsp;{ $mimes[&#8216;svg&#8217;]&nbsp;=&nbsp;&#8216;image\/svg+xml&#8217;; return&nbsp;$mimes; }); } \u767b\u5f55\u540e\u590d\u5236 \u5a92\u4f53\u5e93\u5217\u8868\u6a21\u5f0f\u663e\u793aSVG\u56fe\u7247 \/\/&nbsp;\u5a92\u4f53\u5e93\u5217\u8868\u6a21\u5f0f\u663e\u793aSVG\u56fe\u7247 add_action(&#8216;admin_head&#8217;,&nbsp;function&nbsp;()&nbsp;{ echo&nbsp;&#8220;&lt;style&gt;table.media .column-title .media-icon img[src*=&#039;.svg&#039;]{width: 100%;height: auto;}.components-responsive-wrapper__content[src*=&#039;.svg&#039;] {position: relative;}&lt;\/style&gt;&#8221;; }); \u767b\u5f55\u540e\u590d\u5236 \u7f51\u4e0a\u6709\u5f88\u591a\u4ee5\u4e0a\u7c7b\u4f3c\u7684\u4ee3\u7801\uff0c\u4f46\u90fd\u4e0d\u652f\u6301\u5a92\u4f53\u5e93\u7f51\u683c\u6a21\u5f0f\u663e\u793aSVG\u56fe\u7247\uff0c\u4e0b\u9762\u7684\u4ee3\u7801\u53ef\u4ee5\u5b9e\u73b0\uff1a \/\/&nbsp;\u5a92\u4f53\u5e93\u7f51\u683c\u6a21\u5f0f\u663e\u793aSVG\u56fe\u7247 function&nbsp;zm_display_svg_media($response,&nbsp;$attachment,&nbsp;$meta){ if($response[&#8216;type&#8217;]&nbsp;===&nbsp;&#8216;image&#8217;&nbsp;&amp;amp;&amp;amp;&nbsp;$response[&#8216;subtype&#8217;]&nbsp;===&nbsp;&#8216;svg+xml&#8217;&nbsp;&amp;amp;&amp;amp;&nbsp;class_exists(&#8216;SimpleXMLElement&#8217;)){ try&nbsp;{ $path&nbsp;=&nbsp;get_attached_file($attachment-&amp;gt;ID); if(@file_exists($path)){ $svg&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;new&nbsp;SimpleXMLElement(@file_get_contents($path)); $src&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;$response[&#8216;url&#8217;]; $width&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;(int)&nbsp;$svg[&#8216;width&#8217;]; $height&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;(int)&nbsp;$svg[&#8216;height&#8217;]; $response[&#8216;image&#8217;]&nbsp;&nbsp;=&nbsp;compact(&nbsp;&#8216;src&#8217;,&nbsp;&#8216;width&#8217;,&nbsp;&#8216;height&#8217;&nbsp;); $response[&#8216;thumb&#8217;]&nbsp;&nbsp;=&nbsp;compact(&nbsp;&#8216;src&#8217;,&nbsp;&#8216;width&#8217;,&nbsp;&#8216;height&#8217;&nbsp;); &nbsp; $response[&#8216;sizes&#8217;][&#8216;full&#8217;]&nbsp;=&nbsp;array( &#8216;height&#8217;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&amp;gt;&nbsp;$height, &#8216;width&#8217;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&amp;gt;&nbsp;$width, &#8216;url&#8217;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&amp;gt;&nbsp;$src, &#8216;orientation&#8217;&nbsp;&nbsp;&nbsp;=&amp;gt;&nbsp;$height&nbsp;&amp;gt;&nbsp;$width&nbsp;?&nbsp;&#8216;portrait&#8217;&nbsp;:&nbsp;&#8216;landscape&#8217;, ); } } catch(Exception&nbsp;$e){} } return&nbsp;$response; } add_filter(&#8216;wp_prepare_attachment_for_js&#8217;,&nbsp;&#8216;zm_display_svg_media&#8217;,&nbsp;10,&nbsp;3); \u767b\u5f55\u540e\u590d\u5236 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[],"class_list":["post-31842","post","type-post","status-publish","format-standard","hentry","category-cms"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/31842","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=31842"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/31842\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=31842"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=31842"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=31842"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}