SVG in logo
-
Now that WordPress supports custom logos (https://codex.wordpress.org/Theme_Logo), I would like to use an svg file as my logo.
At line 68 in TwentySixteen’s functions.php file, they already call for support for a custom logo, and a png file works fine, but I can’t get an svg file to work.
I put this in my child theme’s functions.php file so that the uploader would accept svg files:
function me_add_svg_mime_type( $mimes = array() ) { $mimes['svg'] = 'image/svg+xml'; $mimes['svgz'] = 'image/svg+xml'; return $mimes; } add_filter('upload_mimes', 'me_add_svg_mime_type');
That works OK; I can upload my svg files.
Then I added this to my child theme’s functions.php file so that the theme would accept an svg file as a header image:
add_action( 'after_setup_theme', 'me_add_custom_header' ); function me_add_custom_header() { add_theme_support( 'custom-header', array( 'flex-width' => true, 'width' => 1200, 'flex-height' => true, 'height' => 280, 'header-selector' => '.site-title a', 'header-text' => false ) ); }
That works too. When I go to Appearance > Header > Add new image and select my svg file, I get a button that says Select and Crop. WordPress is unable to crop svgs, so the next screen has two buttons, one that says Crop Image and one that says Skip Cropping. 
So that’s all great. I skip cropping and my svg image shows up fine.But when I do what looks to me like the same thing for the logo, it doesn’t work:
add_action( 'after_setup_theme', 'me_add_site_logo' ); function me_add_site_logo() { add_theme_support( 'site-logo', array( 'flex-width' => true, 'width' => 240, 'flex-height' => true, 'height' => 240, 'header-text' => false ) ); }
Then Appearance > Header > back arrow (this shouldn’t be necessary) > Site Identity > Select Logo. If I select a 240x240px png file, it gets placed and all is well. But if I select a 240×240 (page size) svg file, it uploads, but when I come to the cropping step, there’s no Skip Cropping button and the Crop Image button gives the error “There has been an error cropping your image.”
BTW I’m running WordPress locally on MAMP.
I am no code warrior and don’t completely understand what I’m doing, so could someone show me where I’m going wrong?
Thanks —
- The topic ‘SVG in logo’ is closed to new replies.