Support » Plugin: Add Full SVG Support » Is there a way to embed the alt path into the file itself?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Jens

    (@jekuer)

    Hi there,

    I’m not sure if I understood your question correctly. There is no UI element on your editor’s dashboard. You have to use the plugin’s shortcode. There you have to enter the required information (that’s also the file path) manually. It doesn’t matter where the file is located. As long as the relevant servers allow it, you might even be able to point to other domains and servers.
    Did this answer your question?

    Best,
    Jens

    Sorry. I’ll try to clarify: What I’m looking for is an addition to the WordPress media library fields associated with an SVG file that the plugin code recognizes as the path to the alt PNG, when filled out correctly.

    So looking at an SVG’s attachment details would go something like:
    URL
    Title
    PNG alt path
    Caption
    Alt Text

    etc.

    Or if there’s something else to that effect.

    I ask because I want the logo on my site to be an SVG with a PNG alt, but short of altering the theme PHP or .js files, I have no direct way of doing that.

    Hope that’s a little clearer. Thank you.

    Plugin Author Jens

    (@jekuer)

    Ok, I understand.
    This would most probably not work in your case. The reason is that your theme will only see the image path. One would need to hook into the theme. However, there is no general way to do so, because every theme works in a different way.
    The easiest way to achieve what you are looking for, is to change the theme file itself. If you want to keep this change safe for any updates, you can work with a child theme (https://codex.wordpress.org/Child_Themes).

    I also just released an update of the plugin. I included a function that automatically changes every regular image with the svg image as long as they have the same file name and are located in the same folder.
    Please update the plugin, activate the option in the new setting menu, select the png (or jpg) image for your logo, upload the svg file with the same name as the other one to the same folder and check if this works for you. There might be the problem, that the logo does not get any size information. If the svg does not include proper size information, this solution will not work. But simply have a try!

    Best,
    Jens

    Thank you.

    Not sure if this site helps, but here’s where I got the idea:
    http://toddmotto.com/mastering-svg-use-for-a-retina-web-fallbacks-with-png-script/

    Relevant .js

    function supportsSVG() {
      return !! document.createElementNS && !! document.createElementNS('http://www.w3.org/2000/svg','svg').createSVGRect;
    }
    if (supportsSVG()) {
      document.documentElement.className += ' svg';
    } else {
      document.documentElement.className += ' no-svg';
      var imgs = document.getElementsByTagName('img');
      var dotSVG = /.*\.svg$/;
      for (var i = 0; i != imgs.length; ++i) {
        if(imgs[i].src.match(dotSVG)) {
          imgs[i].src = imgs[i].src.slice(0, -3) + 'png';
        }
      }
    }
    Plugin Author Jens

    (@jekuer)

    Hi,

    the approach of Todd is totally different to what I did here. He uses the modernizr script to make svg working. If you would use modernizr, you would not need this plugin ;-).
    So whats the big difference:
    My plugin is very light-weight (as long as you don’t activate the change-all-images-function) and does not depend on any other library or technique. It is also very efficient without great compatibility issues.
    The modernizr approach uses JavaScript. So, you need to load another library. This costs you more time and ressources. It might also either block other content from being loaded or load too late. You also get problems if users deactivated JavaScript and the way it implements the svg image still has some compatibility issues.
    So, of course, you can use the modernizr approach. It gives you more freedom and might fit better to your needs. My plugin is more focused on efficiency. It’s a little like comparing a Leatherman with a tac-ops knife. They both cut, but one is more efficient and one also has a screwdriver. Choose your side 😉

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Is there a way to embed the alt path into the file itself?’ is closed to new replies.