Skip to content

Instantly share code, notes, and snippets.

@jswebschmiede
Created April 2, 2022 20:37
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 jswebschmiede/7ce9f6de4b3d882be6a4b8a871753abf to your computer and use it in GitHub Desktop.
Save jswebschmiede/7ce9f6de4b3d882be6a4b8a871753abf to your computer and use it in GitHub Desktop.
<?php
/**
* Load an inline SVG.
*
* @param string $filename The filename of the SVG you want to load.
*
* @return string The content of the SVG you want to load.
*/
function load_inline_svg( $filename ) {
// Add the path to your SVG directory inside your theme.
$svg_path = '/images/svgs/';
// Check the SVG file exists
if ( file_exists( get_stylesheet_directory() . $svg_path . $filename ) ) {
// Load and return the contents of the file
return file_get_contents( get_stylesheet_directory_uri() . $svg_path . $filename );
}
// Return a blank string if we can't find the file.
return '';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment