Jump to content
You must now use your email address to sign in [click for more info] ×

SVG not showing on website


Recommended Posts

Security reasons, you have to add and enable SVG support in WP!

  • Either use some WP Plugin like „SVG Support“ or „Safe SVG“.
  • Or alternatively try to allow and enable SVG support in functions.php via ...
     
    Quote
    /**
    * Add SVG to allowed file uploads
    **/
    function add_file_types_to_uploads($file_types){
    
    $new_filetypes = array();
    $new_filetypes['svg'] = 'image/svg+xml';
    $file_types = array_merge($file_types, $new_filetypes );
    
    return $file_types;
    }
    add_action('upload_mimes', 'add_file_types_to_uploads'); 
    

    ... OR ...

     /**
     * Add svg support
     **/
    add_filter( 'wp_check_filetype_and_ext', function( $data, $file, $filename, $mimes) {
          global $wp_version;
          if( $wp_version == '4.7' || ( (float) $wp_version < 4.7 ) ) {
          return $data;
        }
        $filetype = wp_check_filetype( $filename, $mimes );
          return [
          'ext'             => $filetype['ext'],
          'type'            => $filetype['type'],
          'proper_filename' => $data['proper_filename']
        ];
    }, 10, 4 );
    
    function dl_mime_types( $mimes ){
       $mimes['svg'] = 'image/svg+xml';
       return $mimes;
    }
    add_filter( 'upload_mimes', 'dl_mime_types' );
    
    function dl_fix_svg() {
      echo '<style type="text/css">.attachment-266x266, .thumbnail img { width: 100% !important; height: auto !important;} </style>';
    }
    add_action( 'admin_head', 'dl_fix_svg' );
    

     

☛ Affinity Designer 1.10.8 ◆ Affinity Photo 1.10.8 ◆ Affinity Publisher 1.10.8 ◆ OSX El Capitan
☛ Affinity V2.3 apps ◆ MacOS Sonoma 14.2 ◆ iPad OS 17.2

Link to comment
Share on other sites

8 minutes ago, garry rigby said:

Hi, yes I have already added code to function page. An SVG I made in adobe illustrator works fine

Check/test it with a SVG Sanitizer and try out any of the cleaned code instead. - The Safe SVG Plugin does the same internally ...

So when in trouble try that one!

☛ Affinity Designer 1.10.8 ◆ Affinity Photo 1.10.8 ◆ Affinity Publisher 1.10.8 ◆ OSX El Capitan
☛ Affinity V2.3 apps ◆ MacOS Sonoma 14.2 ◆ iPad OS 17.2

Link to comment
Share on other sites

Does Wordpress accept width="100%" height="100%" ?

Try the attached file, I've changed those values to match the viewbox
Also cleaned up the text, there was a nasty gap between the S & T
I've also changed STUCCCO to STUCCO
<hint>
Use these options

image.png.708f2bdc97d36aec2fb7c68bdec2b260.png
</hint>

logo2a.svg

Microsoft Windows 11 Home, Intel i7-1360P 2.20 GHz, 32 GB RAM, 1TB SSD, Intel Iris Xe
Affinity Photo - 24/05/20, Affinity Publisher - 06/12/20, KTM Superduke - 27/09/10

Link to comment
Share on other sites

Just now, David in Яuislip said:

Does Wordpress accept width="100%" height="100%" ?

The OP has to test, I don't use/run WP as there are other, better and more secure CMS systems.

☛ Affinity Designer 1.10.8 ◆ Affinity Photo 1.10.8 ◆ Affinity Publisher 1.10.8 ◆ OSX El Capitan
☛ Affinity V2.3 apps ◆ MacOS Sonoma 14.2 ◆ iPad OS 17.2

Link to comment
Share on other sites

8 minutes ago, David in Яuislip said:

Does Wordpress accept width="100%" height="100%" ?

Try the attached file, I've changed those values to match the viewbox
Also cleaned up the text, there was a nasty gap between the S & T
I've also changed STUCCCO to STUCCO
<hint>
Use these options

image.png.708f2bdc97d36aec2fb7c68bdec2b260.png
</hint>

logo2a.svg 368 B · 1 download

Thanks. It does not allow me to upload your file logo2a.svg - which is odd as it uploads other SVG's

Link to comment
Share on other sites

4 minutes ago, v_kyr said:

The OP has to test, I don't use/run WP as there are other, better and more secure CMS systems.

Indeed, I only write plain HTML and I never use Affinity for serious svg's ;-)

Microsoft Windows 11 Home, Intel i7-1360P 2.20 GHz, 32 GB RAM, 1TB SSD, Intel Iris Xe
Affinity Photo - 24/05/20, Affinity Publisher - 06/12/20, KTM Superduke - 27/09/10

Link to comment
Share on other sites

12 minutes ago, garry rigby said:

Thank you but that made no difference.

Just for fun check if the font setting & usage might make trouble here for WP too, thus instead convert the used Logo text to curves in ADe, export as SVG and retry!

☛ Affinity Designer 1.10.8 ◆ Affinity Photo 1.10.8 ◆ Affinity Publisher 1.10.8 ◆ OSX El Capitan
☛ Affinity V2.3 apps ◆ MacOS Sonoma 14.2 ◆ iPad OS 17.2

Link to comment
Share on other sites

1 minute ago, garry rigby said:

Thanks. It does not allow me to upload your file logo2a.svg - which is odd as it uploads other SVG's

 

Just now, v_kyr said:

Just for fun check if the font setting & usage might make trouble here for WP too, thus instead convert the used Logo text to curves, export and retry!

Haha - cool. It works with rasterise to everything and export text curves - thanks for all your help - have a good 1

Link to comment
Share on other sites

18 minutes ago, garry rigby said:

It works with rasterise to everything

Well we don't want any rasterization (pixels/bitmap), we want plain vectors, thus apply just for the selected text layers from the top menu "Layer -> Convert to curves" and export as SVG in a manner that "no rasterization takes place" is shown! - Since you want to have a scalable vector representation and not embedded base64 uuencoded image data (aka pixel/bitmap data). - Check that your final SVG logo contains just vectors and no bitmap based "image" code!

☛ Affinity Designer 1.10.8 ◆ Affinity Photo 1.10.8 ◆ Affinity Publisher 1.10.8 ◆ OSX El Capitan
☛ Affinity V2.3 apps ◆ MacOS Sonoma 14.2 ◆ iPad OS 17.2

Link to comment
Share on other sites

6 minutes ago, v_kyr said:

Well we don't want any rasterization (pixels/bitmap), we want plain vectors, thus apply just for the selected text layers from the top menu "Layer -> Convert to curves" and export as SVG in a manner that "no rasterization takes place" is shown!

oh yeah damn! I exported with text as curves and it works great. thanks again https://www.caracampbell.co.uk/home2/

Link to comment
Share on other sites

20 minutes ago, garry rigby said:

oh yeah damn! I exported with text as curves and it works great.

Looks to be Ok, also contents wise for the SVG XML code itself here (...it's all vectors).

website.jpg.39aed58c35a6be6dff5211dee0d28587.jpg

☛ Affinity Designer 1.10.8 ◆ Affinity Photo 1.10.8 ◆ Affinity Publisher 1.10.8 ◆ OSX El Capitan
☛ Affinity V2.3 apps ◆ MacOS Sonoma 14.2 ◆ iPad OS 17.2

Link to comment
Share on other sites

Just now, garry rigby said:

thanks again for your help

No problem, you're welcome!

☛ Affinity Designer 1.10.8 ◆ Affinity Photo 1.10.8 ◆ Affinity Publisher 1.10.8 ◆ OSX El Capitan
☛ Affinity V2.3 apps ◆ MacOS Sonoma 14.2 ◆ iPad OS 17.2

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.