Created
March 9, 2015 15:24
-
-
Save matesnippets/e0e2b5fae944b01a93af to your computer and use it in GitHub Desktop.
PHP, WordPress, SVG image getter, embed SVG straight to the page, no img tag needed and keeps templated nice and tidy.
This file contains hidden or 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
| /** | |
| * Get SVG file as raw SVG, not img tag | |
| * @param string $path Path to images direcotry | |
| * @param string $file The filename, file extension (.svg) can be omitted | |
| * @return string The contents of the wanted SVG file | |
| */ | |
| function cm_svg_get($path = 'images', $file = '') | |
| { | |
| // $file = $file.".svg"; | |
| $svg = ".svg"; | |
| $file = (substr($file, -strlen($svg)) === $svg) ? $file : $file.$svg; | |
| $abs_path = get_stylesheet_directory() . '/' . $path . '/' . $file; | |
| // Get the file into a a variable | |
| ob_start(); | |
| include $abs_path; | |
| $file = ob_get_contents(); | |
| ob_end_clean(); | |
| return $file; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment