
Allow SVG uploads into your WordPress site using WPCodeBox.
By default, WordPress blocks SVG uploads for security reasons. If you want to use SVGs for logos or graphics, you can allow SVG uploads in WordPress safely with a simple snippet in WPCodeBox.
The snippet checks whether the current user can manage options, which is a capability reserved for administrators. If so, it adds SVG to the list of allowed MIME types, letting admins upload SVG files while keeping restrictions in place for other roles.
This way, administrators get the flexibility to upload SVGs, while non-admin users remain blocked, maintaining security across the site. With just a few lines of code in WPCodeBox, you can extend WordPress to support SVGs exactly where you need them.
Below is the code snippet from the video used to allow SVG uploads in WordPress:
<?php
function allow_svg_for_admins ($mimes) {
if(current_user_can('manage_options')) {
$mimes ['svg'] = 'image/svg+xml';
}
return $mimes;
}
add_filter('upload_mimes', 'allow_svg_for_admins');