I’m trying to use a wordpress function which leads your path to the root of your theme in wordpress by doing:
<img src="<?php bloginfo('template_directory'); ?>/images/art.svg" alt="">
The issue is that if I inspect this I realise that the php code is parsed as a string instead of inserting a path to root of the theme. What am I doing wrong?
FYI: I’m using twig.
I’ve used Twig within Symfony, but never within WordPress. From my experience, in order to access functions such as
bloginfo
you will need to extend Twig to allow it.This will require quite a bit of deep integration, and probably out of the scope of what you’re asking for here.
More information: http://twig.sensiolabs.org/doc/advanced.html#functions
That said, it appears someone has done the hard work for you. Timber is a WordPress to Twig implementation: http://upstatement.com/timber/
Edit: More here, basically the syntax is
{{function('FUNCTION NAME', 'ARGUMENT ONE', 'ARGUMENT TWO')}}
, so in this case:<img src="{{function('bloginfo','template_directory')}}/images/art.svg" alt="">
In Timber the site object holds all your answers. For example…
Then in your twig template…
… for the current theme directory (the equivalent of stylesheet_directory). Or:
… for the current parent theme directory (the equivalent of template_directory).
You forgot to echo out the information.