Last active
December 3, 2020 19:01
-
-
Save elliottmangham/aba38fb9f70e5794e1adb58d14d8922d to your computer and use it in GitHub Desktop.
WordPress (PHP) / Utilities / Serve inline SVG
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
/************************************ | |
* Include SVG file. | |
* @param string $sFilePath The path of the SVG file | |
* @param boolean $bReturn Return the output instead of echoing (optional) | |
************************************/ | |
function get_svg( $sFilePath = NULL, $bReturn = false ) { | |
$sFileContents = NULL; | |
$sSvgPath = THEME_DIR_FILEPATH . '/media/dist/img/' . $sFilePath . '.svg'; | |
if ( is_readable( $sSvgPath ) ) { | |
$sFileContents = file_get_contents( $sSvgPath ); | |
} | |
if ( $bReturn ) { | |
return $sFileContents; | |
} else { | |
echo $sFileContents; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment