Never use PHP short tags for WordPress development

Today while working on a project where we had collaborated with freelance developers I noticed that some pages weren’t looking as they should. A quick glance at the code revealed that the developer was using “short tags” to include the header.

<? get_header ?>

To use short tags, the short_open_tag option must be turned on in php.ini. On most servers short_open_tag is turned on, but alot of servers (like my local server) has it turned off.

If you are developing a theme for a specific server environment, this may be acceptable. But if you are developing a theme or a plugin to be used by a lot of people on a lot of different server environments then short tags can not be used!

Advertisements
About

Web Developer @ Oakwood Creative - www.oakwood.se

Tagged with: , ,
Posted in Best Practices, Misc
3 comments on “Never use PHP short tags for WordPress development
  1. Dave says:

    I don’t follow your logic. Using short tags you can write <?= instead of <?php echo . This saves you 8 keystrokes per variable used in templates, etc. An average website will use this tag thousands of times. Assuming 2000 usages, and a good typist can type one stroke per 0.12 seconds, you save per project 4 minutes. Multiple this by the number of projects you will do per server setup and you are saving a lot of time. Enabling short tags isn't that hard. Using WAMP and its Windows taskbar icon, you can do it in 4 clicks – or about 10 seconds – once and be done with it until the next time your buy a new computer or reformat. For WAMP reference – let click on task tray icon, click on PHP, click on PHP Settings, then click on "open short tag". Done.

    Short tags are awesome.

    • Vincent says:

      Agreed Dave. If you are in control of your server enviornment and you’re only developing for that one enviornment, short tags are perfectly fine and can save you time. But if you’re developing themes and plugins to be used by everyone, using short tags is not an option.

  2. […] a look at the section discussing shorthand PHP tags, an issue I have written about previously. Space usage is also a very common mistake among developers. The correct space usage can really […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

About

WordPress Quick Tips is a blog supplying great tips about WordPress.

We hope to create a great knowledge resource for WordPress developers as well as serving a reminder for all the forgetful ones.

The blog is created and run by Vincent of Oakwood Creative

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 120 other followers

%d bloggers like this: