Way # 1:
function.php
function add_svg_to_upload_mimes( $upload_mimes ) { $upload_mimes['svg'] = 'image/svg+xml'; $upload_mimes['svgz'] = 'image/svg+xml'; return $upload_mimes; } add_filter( 'upload_mimes', 'add_svg_to_upload_mimes', 10, 1 );
Way # 2:
svg.php
/** * Add svg MIME type support * * @param $mimes * * @author fadupla * @return mixed */ function fadupla_mime_types( $mimes ) { $mimes['svg'] = 'image/svg+xml'; return $mimes; } add_filter( 'upload_mimes', 'fadupla_mime_types' ); /** * Enqueue SVG javascript and stylesheet in admin * @author fadupla */ function fadupla_svg_enqueue_scripts( $hook ) { wp_enqueue_style( 'fadupla-svg-style', get_theme_file_uri( '/assets/css/svg.css' ) ); wp_enqueue_script( 'fadupla-svg-script', get_theme_file_uri( '/assets/js/svg.js' ), 'jquery' ); wp_localize_script( 'fadupla-svg-script', 'script_vars', array( 'AJAXurl' => admin_url( 'admin-ajax.php' ) ) ); } add_action( 'admin_enqueue_scripts', 'fadupla_svg_enqueue_scripts' ); /** * Ajax get_attachment_url_media_library * @author fadupla */ function fadupla_get_attachment_url_media_library() { $url = ''; $attachmentID = isset( $_REQUEST['attachmentID'] ) ? $_REQUEST['attachmentID'] : ''; if ( $attachmentID ) { $url = wp_get_attachment_url( $attachmentID ); } echo $url; die(); } add_action( 'wp_ajax_svg_get_attachment_url', 'fadupla_get_attachment_url_media_library' );