how to allow svg image in WordPress via code

0
8K
  1. Theme Functions File: You can allow SVG uploads by adding custom code to your theme's functions.php file. Here's how to do it:

    a. Access your WordPress admin dashboard.

    b. Navigate to "Appearance" and select "Theme Editor."

    c. Find and select the functions.php file on the right-hand side.

    d. Add the following code to the functions.php file:

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

    This code adds SVG as an allowed file type for uploads.

  2. Save Changes: After adding the code, click the "Update File" button to save the changes to your functions.php file.

  3. Test SVG Uploads: You should now be able to upload SVG files via the WordPress media uploader. Navigate to "Media" > "Add New" and try uploading an SVG file to test if it works.

Please remember to exercise caution when allowing SVG uploads, as they can potentially contain harmful code. You may want to consider implementing additional security measures, such as using a security plugin, to help protect your WordPress site from potential security risks associated with SVG files.

Lastly, always keep your WordPress core, themes, and plugins up to date to ensure the latest security patches are applied.

Search
Sponsored
Sponsored
WordPress Quick Solution
Categories
Read More
Networking
India Awards Padma Bhushan to Foxconn CEO Taiwan
India's Republic Day is all about traditions and one of them is the Padma Awards the winners are...
By abhira 2024-01-27 10:48:54 0 6K
Shopping
Nubia Z60 Ultra, which the world is waiting for!
The moment the world has been waiting for is here. Nubia Z60 Ultra, a smartphone that combines...
By abhira 2023-12-18 17:36:12 0 8K
Other
Steps to Build Your Own Delivery App Like GoPuff Clone App With Features
If you're looking to venture into the delivery app market and build your own GoPuff clone app,...
By smithjoe 2023-10-19 07:20:06 0 9K
Networking
Using GraphQL in WordPress: A Comprehensive Guide
The History of GraphQL GraphQL, much like React, was originally developed by Facebook. The...
By Wp India 2024-06-26 17:32:35 0 3K
Networking
Understanding File Permissions and Their Role in WordPress Security
Understanding File Permissions and Their Role in WordPress Security File permissions are an...
By abhira 2025-02-28 18:03:21 0 3K
Abhira Social Media https://abhira.in