Last active
April 5, 2018 08:43
-
-
Save GarySwift/3d1ce6d98f99ea919b6284ddd4220dd5 to your computer and use it in GitHub Desktop.
SVG in PHP example #WordPress. It uses the PHP function 'file_get_contents' to output an inline SVG from an SVG image file.
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
.logo { | |
svg { | |
.cls-1{ | |
fill:none; | |
stroke: get-color('primary'); | |
} | |
.cls-2{ | |
fill: get-color('primary'); | |
} | |
} | |
} |
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
<?php | |
function svg($filename, $folder='svg') { | |
$file = "/dist/assets/images/$folder/$filename.svg"; | |
$file_path = get_stylesheet_directory().$file; | |
$file_uri = get_stylesheet_directory_uri().$file; | |
if (file_exists ( $file_path )) { | |
return file_get_contents($file_uri); | |
} | |
} |
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
<!-- Use PHP to place inline SVG from file - expects file '/dist/assets/images/svg/logo.svg' --> | |
<a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home" class="logo"><?php | |
echo svg('logo); | |
?><span class="hide"><?php bloginfo( 'name' ); ?></span></a> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment