Skip to content

Instantly share code, notes, and snippets.

Created May 6, 2016 20:59
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
PHP: WordPress echo SVG file contents for inline SVG
<?php echo file_get_contents( get_stylesheet_directory_uri() . '/img/awesome.svg' ); ?>
Copy link

Also, try using get_template_directory() instead of get_template_directory_uri()

Use something like:
<?php echo file_get_contents(get_template_directory().'/theme/img/chevron-right-solid.svg'); ?>

Sometimes using get_template_directory_uri() will throw an SSL error

Then, you can target the SVG and style how you wish.
For example:

<button class="btn btn-primary">
  <?php echo file_get_contents(get_template_directory().'/theme/img/chevron-right-solid.svg'); ?>

CSS might be:

.btn svg { line-height: 1.2; max-height: 1rem;}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment