简体   繁体   中英

Code outputting html instead of an image?

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?

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" />'; }?>

Have you tried this:

$template_url = get_bloginfo('template_url');

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM