WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] PHP code "jumping" around html

[Resolved] PHP code "jumping" around html

  • Hi!
    I’m rather new to PHP and WP, and I have recently stumbled upon this odd behaviour. It might be some standard in PHP, but I haven’t been able to find any documentation about it.

    Here it goes. I have this rather simple code:
    echo "<img src='" . bloginfo('template_directory') . "/css/imagenes/p_2.jpg' blabla..."

    which, oddly enough, outputs this to html:
    http://localhost:8888/wp-content/themes/Starkers<img src='/css/imagenes/puntuaciones/p_2.jpg' blabla...

    As you can see, the code generated by bloginfo() jumps to the beginning of the html statement, messing the whole thing up.
    I know I could recode the whole thing as
    <img src="<?php echo bloginfo(); ?>" ectcetera>
    but I’d rather not do it, because it’s located in a php chunck of code which would get quite messy if I did.

    Am I doing anything wrong?
    Thanks a lot.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Fix

    echo "<img src='" . get_bloginfo('template_directory') . "/css/imagenes/p_2.jpg' blabla..."

    You need a return value inside an echo statement, bloginfo echoes it’s value (so not suited), but get_bloginfo gives you a return value, which will work appropriately inside the echo statement.

    Right, that sounds pretty reasonable, Mark. Easy enough 🙂
    Thanks!

    You’re welcome… 🙂

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Resolved] PHP code "jumping" around html’ is closed to new replies.