fahimmurshed

Enable SVG Support in WordPress

Sep 25th, 2021 (edited)
340
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.80 KB | None | 0 0
  1. // Allow SVG
  2. add_filter( 'wp_check_filetype_and_ext', function($data, $file, $filename, $mimes) {
  3.  
  4.   global $wp_version;
  5.   if ( $wp_version !== '5.7.1' ) {
  6.      return $data;
  7.   }
  8.  
  9.   $filetype = wp_check_filetype( $filename, $mimes );
  10.  
  11.   return [
  12.       'ext'             => $filetype['ext'],
  13.       'type'            => $filetype['type'],
  14.       'proper_filename' => $data['proper_filename']
  15.   ];
  16.  
  17. }, 10, 4 );
  18.  
  19. function cc_mime_types( $mimes ){
  20.   $mimes['svg'] = 'image/svg+xml';
  21.   return $mimes;
  22. }
  23. add_filter( 'upload_mimes', 'cc_mime_types' );
  24.  
  25. function fix_svg() {
  26.   echo '<style type="text/css">
  27.        .attachment-266x266, .thumbnail img {
  28.             width: 100% !important;
  29.             height: auto !important;
  30.        }
  31.        </style>';
  32. }
  33. add_action( 'admin_head', 'fix_svg' );
Add Comment
Please, Sign In to add comment