Skip to content

Instantly share code, notes, and snippets.

@jenswittmann
Last active February 3, 2021 14:22
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 jenswittmann/54fd51e12ab1d738d1673b7486e09531 to your computer and use it in GitHub Desktop.
Save jenswittmann/54fd51e12ab1d738d1673b7486e09531 to your computer and use it in GitHub Desktop.
Timber embed SVG Plugin for WordPress
/**
* 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