Created
January 25, 2016 21:29
-
-
Save spigotdesign/4e493d5678daeaa8d266 to your computer and use it in GitHub Desktop.
WordPress get SVG file contents
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php echo file_get_contents( get_stylesheet_directory_uri() . '/img/icons/your-logo-file.svg' ); ?> |
Since Wordpres 4.7.0 there is cleaner way for getting files from parent/child theme using these function:
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'); ?>
</button>
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
Wont using the
.._uri()
variant makefile_get_contents
fetch the file over the network, rather than from the filesystem? It seems like usingget_stylesheet_directory()
withfile_get_contents
is a bit better