PHP WordPress quotes issue

Having a quotes issue, need a second pair of eyes!

echo "<img src='" . bloginfo('template_url') . "img/" . $f['mainImage'] . ".png' />";

Using the WordPress function bloginfo to get the theme path!

Read More

All i’m getting is the path printed out on the page, no image!

Thanks

What is output:

 http://www.example.co.uk/wp-content/themes/example
<img src="/img/digital.png">

Related posts

Leave a Reply

3 comments

  1. bloginfo() is only used to directly output the requested value. Use get_bloginfo() instead to work with the value before echo’ing it.

    echo sprintf(
        '<img src="%s/img/%s.png" />', 
        get_bloginfo('template_url'), 
        $f['mainImage']
    );
    
  2. As jnpcl has surmised, it looks like bloginfo() is print out the data for you.

    You’ve got two options:

    • use the get_bloginfo() function, which wont just print it out but return it instead
    • Take that into account, echo part of the image tag, call the function, echo the rest