Skip to content

Instantly share code, notes, and snippets.

@elliottmangham
Last active December 3, 2020 19:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elliottmangham/aba38fb9f70e5794e1adb58d14d8922d to your computer and use it in GitHub Desktop.
Save elliottmangham/aba38fb9f70e5794e1adb58d14d8922d to your computer and use it in GitHub Desktop.
WordPress (PHP) / Utilities / Serve inline SVG
/************************************
* 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