0

Here is the code that I am referring to:

<?php if ( is_archive() ) { echo '<img src="'.bloginfo('template_url').'/images/test.png" />'; }?>

This is what the code outputs: http://site.com/wp-content/themes/themename

I'd like it to output the actual image in the code. What part of this did I overlook?

4
  • Can you be more specific. The current code will output the <img src="whateverurl/image/test.png" /> Commented May 19, 2012 at 3:56
  • The code you have written isn't going to output what you say it does. It's either going to output an image tag or nothing Commented May 19, 2012 at 3:56
  • That's very strange. On my screen, it's showing exactly what I put up there. I was thinking there may possibly be an error in the code but I can't seem to find one. Commented May 19, 2012 at 3:58
  • Oh yes. It shows that because bloginfo actually echo's the output . it doesnt return string. Commented May 19, 2012 at 3:59

2 Answers 2

1

bloginfo() doesn't output the string. It echo's it directly to output stream. So, the code should be:

<?php if ( is_archive() ) { ?>
   <img src="<?php bloginfo('template_url'); ?>/images/test.png" />'; 
<?php  }  ?>

Or else, you can use get_bloginfo() :

<?php if ( is_archive() ) { echo '<img src="'.get_bloginfo('template_url').'/images/test.png" />'; }?>
Sign up to request clarification or add additional context in comments.

Comments

0

Have you tried this:

$template_url = get_bloginfo('template_url');

<?php if ( is_archive() ) { echo '<img src="'.$template_url.'/images/test.png" />'; } ?>

2 Comments

You can't use this. If you want to store values from bloginfo into variables , you are supposed to use get_bloginfo() not bloginfo()
I've already given the answer. No need to edit it to the correct code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.