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

Was it good/ useful/ a load of old rubbish? Let me know on Mastodon, or BlueSky (or Twitter X if you must).

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

31 May 2007

WordPress tips and tricks – functions.php

Functions.php is a little known wordpress template file. Not many themes take advantage of it but , used properly, it can be incredibly powerful. The file can be used as a way to add your own functions to wordpress themes...
20 Jul 2016

Empathy in Web Design

I wasn’t able to make WordCamp Europe this year, but they’ve been really quick at getting all of the talks online, and so I have been watching some of them – and this one stood out.Morten Rand-Hendriksen is an experienced...
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...
11 Apr 2011

Optimizing WordPress 404’s

One of the great things about WordPress is how 404 error pages are handled. If a page isn’t found then you can show a proper dynamic error page giving the user things to do – this removes a lot of...
27 May 2013

WordPress: 10 Years Young, What Does The Future Hold?

WordPress is now 10 years old. I started using wordpress 9 years ago – which means I joined the WordPress community early on. The reason I chose WordPress is simply because of the fabled 5 minute install process – I...