当前位置:网站首页>WordPress media library supports uploading and previewing SVG icons

WordPress media library supports uploading and previewing SVG icons

2022-06-21 08:14:00 Ashi

WordPress By default, it supports a variety of image formats, including .jpg,.jpeg,.png, and .gif, For security reasons, scalable vector graphics cannot be uploaded (SVG).SVG Is one of the most flexible image types , It's based on XML Vector image of , Websites can usually use it to display logos and icons on their websites . SVG The main reason for growing popularity is the scalable image format , Usually the file size is small ( Sometimes quite large ), And will not be pixelated on the retina screen , Don't like jpg,png Such as the image format that is easy to blur .

Let the media library support SVG Upload

/* Add media library  SVG  Icon support */function salong_mime_types($mimes) {  $mimes['svg'] = 'image/svg+xml';  return $mimes;}add_filter('upload_mimes', 'salong_mime_types');

Show in media library SVG Icon

/* Show in media library  SVG  Icon */function salong_admin_svg_css() {    echo "<style>table.media .column-title .media-icon img[src*='.svg']{        width: 100%;        height: auto;    }</style>";}add_action( 'admin_head', 'salong_admin_svg_css' );

Both of the above code are added to the topic functions.php Function file .

原网站

版权声明
本文为[Ashi]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202221502095767.html