Writing Code for Users Who Don’t Code

I have many clients who hack at their code using the Dashboard > Appearances > Editor. It’s OK since I get the call and the $ to fix things if they hack it wrongtease. And after all, it is their website and it is kinda exciting, even addictive, to see what happens when you hack on code!

So, when I write custom  loops, I like to use a pattern that is a) not recommended by the WordPress coding standards handbook or b) preferred by real developers.

Real Developers and the WordPress Coding Standards Handbook recommend using brackets

<?php
if ( have_posts() ) {
  while ( have_posts() ) {
    the_post();
     //
     // Post content here
     //
  } 
} 

While I prefer

<?php
if ( have_posts() ) :
  while ( have_posts() ) :
    the_post();
     //
     // Post Content here
     //
  endwhile;
endif;

Why?

The second method “reads” better for the novice in looking at code. Read the colon, :, as then which is what we normally read it in English: <– means then this. The code reads If have posts, then while have posts, then do the posts. After doing the posts, end while we have posts; end if we have posts.

I try to use this for the novice user but sometimes, yes, I forget laugh