Disable PHP Short tags

A quick tip for any WordPress devs out there (or any other devs for that matter). Don’t use PHP short tags!

PHP Short Tags

I’ve been bitten by this more than once in the past. Some servers allow PHP short tags (<?) and others don’t (<?php) and so when distributing your code it will look broken to some people – and work fine for others.

For me PHP Short Tags have been an issue when creating WordPress themes for Pro Theme Design. As such I learnt my lesson a long time ago – but as this recent post from Konstantin (a developer at Automattic) shows – even the best get caught out sometimes.

You could argue that if you’re only making ‘things’ for yourself that it doesn’t matter – but even then it’s not guaranteed. If you ever have to move server/ web host, or if your PHP settings get changed by your host, you could end up in the situation that stuff breaks and you’re not sure why.

I think the best way to solve this is to simply disable short tags in php.ini.

Doing this is really, and can be done in a couple of ways.

Disable PHP short tags with php.ini

All you have to do is load up php.ini and add/ change the following line, and then restart apache (I normally do this through my web host control panel):

short_open_tag=Off

Disable short tags with .htaccess

This is actually my preferred method because it’s so much simpler – and since I work with WordPress so much I always have a .htaccess file to hand. Just open up your .htaccess file and add the following line:

php_value short_open_tag 0

How was it for you? Let me know on BlueSky or Mastodon

(Please) Link to this page

Thanks for reading. I'd really appreciate it if you'd link to this page if you mention it in your newsletter or on your blog.

Related Posts

01 Apr 2015

The State of WordPress Themes #wcldn

I recently spoke on a panel at WordCamp London 2015e. Lance – who used to be the Theme Team lead at WordPress.com – asked me if I wanted to speak on a panel with him at WordCamp London 2015. I’ve...
04 Nov 2016

Automating WordPress Development with Gulp, Bash, and PHP

When I wrote about the things I had learned from releasing 20 WordPress themes, I mentioned that I had automated as much as I could. One of the things I automated was the build and deployment process for my themes...
13 Oct 2016

Lessons Learned from 20 Theme Releases on WordPress.com

In 2007 I partnered with Darren Hoyt to release Mimbo Pro, one of the earliest premium WordPress themes. In 2012 Mimbo Pro was published on wordpress.com. Last week – on October 5th 2016 to be precise – my 20th theme...
14 Mar 2009

Mimbo Pro 2.0

A year ago – almost to the day – Darren and I released Mimbo Pro, a premium WordPress theme. Since then both WordPress, and our technical skills, have grown considerably and so we’re now ready to present to you, Mimbo...
13 May 2010

6 Tips to Build Better WordPress Themes

If you want to make WordPress themes, for clients, to release for free or to sell, then there are a lot of factors you need to take into consideration. Below are some hints and tips that should help ease your...
08 Aug 2013

The Death of WordPress Theme Frameworks

WordPress theme frameworks are on their way out. They’re dying a slow death. At least that’s what I think.Nathan Rice recently wrote an article with his thoughts about theme frameworks – in defense of them – however he clearly has...