WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Use of PHP in theme files and echo... (5 posts)

  1. t31os
    Member
    Posted 5 years ago #

    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...

  2. iridiax
    Member
    Posted 5 years ago #

    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.

  3. t31os
    Member
    Posted 5 years ago #

    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..

  4. caemusic
    Member
    Posted 5 years ago #

    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.

  5. t31os
    Member
    Posted 5 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic