prashantdwivedi

Enable SVG Support in WordPress

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