SVG / single-image / output as "inline"-string

Support MB Custom Post Type SVG / single-image / output as "inline"-string

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #39106
    jw_blnjw_bln
    Participant

    Hi,
    in a CPT-loop I am trying to insert an SVG from the WP media gallery.
    BUT it has to be inserted inline (no src possible, to be able to manipulate the SVG).

    Question: Using MB, is there any simple way to "transform" and output the inline string of a "single_image"?

    //
    Media Galery Example ID=xyz looks like this:
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M15.84 10.2L14.83.........." /></svg>

    I am looking to output something like this on a page:
    <div>
    <svg class="xxx" id="svg-sitemap" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M15.84 10.2L14.83.........."></path></svg>
    </div>

    #39126
    PeterPeter
    Moderator

    Hello there,

    It is not possible to save the SVG image with string code in the database. This field saves the image ID to the database as you can read on the documentation https://docs.metabox.io/fields/single-image/

    If you want to save the image code, please use the field textarea or text for this case.

    #39134
    jw_blnjw_bln
    Participant

    Hi,
    I spoke about "transform".

    All SVG's are already in the media library; so there is no need to have it in the DB.
    Image single also exists.
    ONLY the output format is missing in MB.

    You simply can use PHP functions require or include in your code base to be able to output the content.

    This is my simple example, maybe you have a better approach:

    <?php 
      function svg_include($file_name, $site_url) {
      	$file = $site_url . '/wp-content/uploads/' . $file_name . '.svg';
      	$output = require ($file);
      	return $output;
      }
    ?>

    I would like to use this function.
    But unfortunately, this is not possible in certain situations ;-(
    That's the reason why I am asking - I think it would bring MB also a benefit, without much effort...

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.