Support » Themes and Templates » Use of PHP in theme files and echo…

  • Resolved t31os

    (@t31os)


    Hi guys (& gals),

    Been using WP a little while now, and not working hugely on the site, it’s mainly a side project/hobby to spend time on.

    Anyway, my question is in relation to using PHP inside template files…

    Often i see code like this…

    <?php if_something() { ?>something<?php } ?>

    Is there a particular reason coders are avoiding just using echo in the php?

    I just personally prefer to echo out what i need, but wondered if there was a particular reason to use the above method over echo statements.

    I would assume not, but it cannot hurt to ask aye? 🙂

    Thanx in advance for any feedback…

Viewing 4 replies - 1 through 4 (of 4 total)
  • Is there a particular reason coders are avoiding just using echo in the php?

    Yes, it’s much easier than trying to echo a big chunk of html. This way, the html can be used without modification. If you want to see the other extreme (everything echoed), check out the German Newspaper theme.

    Not easier at all, for me i prefer the echo’ing….

    Alot of people still about over using echo’s though….

    I see this alot…

    echo 'something';
    echo 'something else';
    echo 'something more';

    When you could just be doing…

    echo 'something
    something else
    something more';

    When i’m building something in PHP i find it much easier to use the echo’s in terms of readability and keeping track of what my php is doing…

    Using <?php ?> all over the place just makes the code an eyesore for me.

    Thanks for the clarification though… appreciate the response..

    i agree echoing html is sort of a hassle – escaping quotes and such. if it’s a huge chunk of html then it’s much easier to use the method you mentioned.

    Ya know, i don’t actually mind the code in the theme linked, it’s not over the top and it’s easy to read.

    I’d personally divide the code up a little more with includes, but i find that just as easy to read.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Use of PHP in theme files and echo…’ is closed to new replies.