Add SVG Support for logo upload. WordPress code example open

Add SVG Support for logo upload. WordPress code example

Approved. Code works!
This is exactly the working code that is verified by the moderator or site administrators
Tested: PHP 5.6 +

First of all, you need to make sure that the system allows you to download svg files. To do this, add the following code to your function.php:

//allow svg files
require get_template_directory() . '/inc/customizer.php';
function cc_mime_types($mimes) {
    $mimes['svg'] = 'image/svg+xml';
    return $mimes;
}
add_filter('upload_mimes', 'cc_mime_types');
[php]

Carefully check that the parameters have been added '<i>flex-width' => true</i>, '<i>flex-height' => true</i>,  in the initialization function of your logo (try find them in function.php):

[php]
function custom_theme_setup () {
add_theme_support(
        'custom-logo',
        array(
            'height' => 250,
            'width' => 250,
            'flex-width' => true,
            'flex-height' => true,
        )
    );
}
//add on hook after_setup_theme
add_action('after_setup_theme', 'custom_theme_setup');
! Upload a logo that no longer needs the crop function. It will not work with svg.
! Be careful that the container in which the logo is located may not have a clearly defined height. The logo will simply not be added to the site. To display the logo, add a minimum height in CSS:
.logo-container {
 min-height:250px;
}
0

More

Leave a Reply

Your email address will not be published. Required fields are marked *

How many?: 22 + 22

lil-code© | 2022 - 2024
Go Top
Authorization
*
*
Registration
*
*
*
*
Password generation