Skip to content

Instantly share code, notes, and snippets.

@jenswittmann
Last active July 3, 2024 18:10
Show Gist options
  • 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