Use PHP’s alternative syntax for clearer WordPress templates

I’ve seen quite a few instances of people asking when and where to use PHP’s alternative syntax for control structures and if you don’t know what I’m referring to, check out the PHP documentation for an outline.

There’s no hard and fast rule for when to use the alternate syntax but personally, I much prefer the alternative syntax for template use. I never use it in blocks of PHP code but I always use it when I’m writing templates. I just find it a whole lot more readable than trying to find the closing brace wrapped in PHP tags in amongst a bunch of HTML markup.

Here is a look at what a basic WordPress template looks like when using the alternative syntax:

The endif and endwhile tags are just so much clearer in amongst template code.

One last thing…

If you liked this article, I'd be incredibly grateful if you tweeted about it.

Also, I don't send emails often but when I do, I try to fill them full of useful goodies. If you like code snippets & dev tips, join my mailing list. There's no catch but I'll probably want to tell you about any new plugins & tools I build.