Skip to content

Instantly share code, notes, and snippets.

@patric-boehner
Created July 4, 2019 01:39
Show Gist options
  • Save patric-boehner/86eb9320888934b909c454508bbedf31 to your computer and use it in GitHub Desktop.
Save patric-boehner/86eb9320888934b909c454508bbedf31 to your computer and use it in GitHub Desktop.
Include inline SVG files.
<?php
function pb_load_inline_svg( $filename ) {
// Add the path to your SVG directory inside your theme.
$svg_path = '/assets/svg/';
$file_end = '.svg';
//Check the SVG file exists
if ( ! file_exists( CHILD_DIR . $svg_path . $filename . $file_end ) ) {
// Return a blank string if we can't find the file.
return '';
}
// Load and return the contents of the file
return file_get_contents( CHILD_DIR . $svg_path . $filename . $file_end );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment