2

I'm currently working on a theme that enables the user to upload a logo via the customize theme page.

I want the user to be able to upload an SVG as a logo.

Wordpress does not allow SVG's to be uploaded by default. So I used a snippet of code to enable SVG's in de media uploader.

function cc_mime_types( $mimes ){
    $mimes['svg'] = 'image/svg+xml';
    return $mimes;
}
add_filter( 'upload_mimes', 'cc_mime_types' );

I figured this would also allow me to upload SVG's via the customize theme page (customize.php) .

This doesn't seem to work.

When I upload an svg via the normal media uploader, the file gets uploaded succesfull. When I try to upload an svg via my logo uploader on the customize theme page, nothing happens. Not even an error.

My code to enable logo uploading via the customize theme page:

function themeslug_theme_customizer( $wp_customize ) {
    $wp_customize->add_section( 'themeslug_logo_section' , array(    
    'title'       => __( 'Logo', 'themeslug' ),
    'priority'    => 30,
    'description' => 'Upload a logo to replace the default site name and description     in the header',
) );
$wp_customize->add_setting( 'themeslug_logo' );
$wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize,     'themeslug_logo', array(
    'label'    => __( 'Logo', 'themeslug' ),
    'section'  => 'themeslug_logo_section',
    'settings' => 'themeslug_logo',
) ) );
}
add_action('customize_register', 'themeslug_theme_customizer');

Does anyone know how to enable SVG upload specificaly for the customize theme page?

4

You'll also need to add "svg" to the list of valid extensions in WP_Customize_Image_Control:

$wp_customize->add_control(
    new WP_Customize_Image_Control(
        $wp_customize,
        'themeslug_logo',
        array(
            'label'      => __( 'Logo', 'themeslug' ),
            'section'    => 'themeslug_logo_section',
            'settings'   => 'themeslug_logo',
            'extensions' => array( 'jpg', 'jpeg', 'gif', 'png', 'svg' ),
        )
    )
);
  • Exactly what I was looking for. I wonder why I couldn't find this info. – user25312 Aug 30 '14 at 16:27
  • AFAIK it's not documented. Found it browsing the source :) – TheDeadMedic Aug 30 '14 at 16:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.