Last active
July 3, 2024 18:10
-
-
Save jenswittmann/54fd51e12ab1d738d1673b7486e09531 to your computer and use it in GitHub Desktop.
Timber embed SVG Plugin for WordPress
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
/** | |
* embed SVG | |
* Example: <span>{{ "logo"|svg }}</span> | |
* | |
* @param \Twig\Environment $twig The Twig environment. | |
* @return \Twig\Environment | |
*/ | |
function twig_svg_embed($twig) | |
{ | |
$twig->addFilter( | |
new Timber\Twig_Filter("svg", function ($name) { | |
return file_get_contents( | |
"wp-content/themes/{themename}/icon/" . | |
$name . | |
".svg" | |
); | |
}) | |
); | |
return $twig; | |
} | |
add_filter("timber/twig", "twig_svg_embed"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment