WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] PHP code "jumping" around html (4 posts)

  1. bnvt
    Member
    Posted 3 years ago #

    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.

  2. Mark / t31os
    Moderator
    Posted 3 years ago #

    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.

  3. bnvt
    Member
    Posted 3 years ago #

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

  4. Mark / t31os
    Moderator
    Posted 3 years ago #

    You're welcome... :)

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags