how to allow svg image in WordPress via code

0
7K
  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
Categories
Read More
Other
Build a Successful Multi-Delivery Service App With a Glovo Clone App
Creating a successful multi-delivery service app like Glovo requires careful planning, robust...
By smithjoe 2023-10-06 06:47:33 0 9K
Other
Yemen has declared war against Israel?
In Dubai, the United Arab Emirates, Houthi rebels from Yemen launched a missile and drone attack...
By tarun 2023-10-31 18:40:06 0 6K
Other
E-Commerce Development Services
The Nth Bit Labs is a trustworthy provider of E-Commerce Development Services in India. With a...
By thenthbit 2023-10-07 07:28:40 0 8K
Other
How to Successfully Implement an Bolt Clone App for Your Taxi Business
Implementing a Bolt clone app for your taxi business can be a strategic move to stay competitive...
By smithjoe 2023-10-27 05:19:47 0 7K
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 8K