Out, Damn’d Quote!

The Shakespearean Flaw in PHP Prompts
WordPress’ White Screen of Death

Thus conscience does make cowards of us all,
And thus the native hue of resolution
Is sicklied o’er with the pale cast of thought,
And enterprises of great pitch and moment
With this regard their currents turn awry,
And lose the name of action

— William Shakespeare, Hamlet, Act III Sc.1

Alas poor Yorick! He couldn't code worth a fiddler's damn, Horatio.Okay, maybe the potential fragility of computer language code, specifically PHP as utilized by WordPress, doesn’t quite compare with Hamlet’s dawdling and proto-angst or Macbeth’s murderous ambition – their fatal, tragic flaws, if you are a Shakespeare buff, or at least were paying attention in high school English. Indeed, exaggeration of Swiftian proportions, this. But this fragility can bring on the dreaded WordPress White Screen of Death quite easily when one begins modifying code (code that works just fine as it is) to customize it to one’s own wants and needs.

In fact, one misplaced apostrophe – or, rather, one misinterpreted single quote — can break an entire installation of WordPress, prompting the aforementioned White Screen of Death. Think of the thousands of lines of code involved in a Website, WordPress or otherwise, and then think about that. Here is this magnificent digital tower: a fortress of light standing staunchly at the crossroads of Gibson’s cyberspace, destroyed (albeit temporarily) by one tiny, misplaced, digital brick.

It’s not just tragic – okay, not really – but also ironic in that one of the great things about WordPress is that it’s open source, has lots of really knowledgeable coders working on it, and as such is really stable. Someone who doesn’t know jack squat about computers and the series of interconnected tubes can get WordPress up and running with relative ease and speed, joining their voice to the cacophony of the blogosphere. It’s actually quite hard to break WordPress, in point of fact. It’s like my old Subaru: until you go tinkering under the hood fixing stuff that isn’t broken, it works flawlessly.

Case in point: I was recently working on a site that will use WordPress and the Thirty Ten theme, which is a three-column version of WordPress’ own Twenty Ten theme, the default theme that comes with WordPress. I wanted something as simple and clean as Twenty Ten for this particular site, but, I wanted three columns. Rather than reinvent the three-columned wheel, I looked to Aaron Jorbin’s Thirty Ten theme.

This is exactly what I wanted: a child theme of Twenty Ten that adds a third column. Yay for Aaron Jorbin! I only needed to change the link colors and add custom text to the footer.

I wasn’t quite thinking when I attended to the latter; after all, what could go wrong, just replacing text? You can see the tragic Shakespearian downfall coming, yeah? PHP uses single quotes around text that will appear in your browser. For example, if we look at the footer.php file in Twenty Ten, there is this line:

<?php printf( __( ‘Proudly powered by %s.’, ‘twentyten’ ), ‘WordPress’ ); ?>

Lady Macbeth looks for the problem in her PHP code. That line produces the “Proudly powered by WordPress.” line at the bottom of every page in the default Twenty Ten theme. Thirty Ten modifies this, along with some of the other default text that appears elsewhere in the Twenty Ten theme, with a file called text-wrangler.php – the beauty of a child theme is that it doesn’t modify the underlying parent theme files. Among my customized footer text were the word’s “Gecko’s Bark” – no, really. Now, an experienced Web coder would know that single quote, doubling as a possessive apostrophe in this instance, would have to represented by the proper code for its symbol, lest a browser interpret it as part of the actual PHP code. Specifically, I needed Gecko&#39;s Bark.

But I’m still a n00b, really – well not really a n00b, after all, I realized where my problem lay within minutes. But I obviously lack the expertise and instincts that someone that has coded all his her life, for a living. Ironically, if I hadn’t been a journalist all my life, being grammatically correct wouldn’t be instinctive and I probably wouldn’t have sweated the possessive. So there you go; my own tragically Shakespearean flaw in miniature.

Anyway, that little coding boo-boo was enough to completely break WordPress. I went to look at how the footer appeared with the changes, and … nothing. Zilch. Nada. It was a sea of white space in the browser. I tried to go to the WordPress admin page, but saw only more white space.

Yep. One little single quote caused a cascade effect that broke WordPress completely. Usually something like this will only cause certain pages not to load, or the site and/or the admin pages to look wonky. Or you get some sort of PHP-related error. But not this time; I tried different browsers and there was nothing but white space or the “can’t get there from here” error that Internet Explorer throws up. That little misplaced single quote caused my browser to subsequently misinterpret all of the rest of the underlying code that otherwise works fine.

Fortunately this wasn’t a live site (the beauty of having a local WordPress installation). I looked at the MySQL database and restarted Apache – typically the rare WordPress White Screen of Death involves issues with one these things – but neither one of these were the problem. I would have been surprised if either had; the site was working moments before I went to tinker with the footer text, now it was busted – doesn’t take Sherlock Holmes to logically deduce that I must have broke things messing around with that footer text. Sure enough, a perusal of text-wrangler.php revealed the problem.

The damn'd spot, er, apostrophe cum single quote in question. D’oh! Out, damn’ed quote!

This is where it’s nice to have a text editor that can represent different parts of code with different colors; in this case the telltale devil was in the pink text, or lack thereof. When looking at PHP code in Gedit, the text editor in versions of Linux that use the Gnome GUI, such as Ubuntu, it portrays text in between quotes — the text that will appear in your browser — in bright-pink-not-quite-fuchsia. A quick glance revealed my errant apostrophe and the subsequent line of text that should have been pink, but wasn’t.

No, not the stuff of Shakespearean tragedy. Not even comedy. But hopefully this will server as a warning and lesson to others who set out to customize WordPress. Be careful tinkering under the hood, lest your hubris cause your tragic downfall – or that of your Website.

To-morrow, and to-morrow, and to-morrow,
Creeps in this petty code from screen to screen
To the last syllable of re-coded line;
And all our yesterdays have lighted fools
The way to white screen death. Out, out, brief mon’tor!
Website’s but a walking shadow

– Jeff Chappell (with apologies to the Bard. To see the inspiration/original, consult Macbeth, Act V, Sc. V).

If you’d like more Shakespearean parody, please go here.

4 thoughts on “Out, Damn’d Quote!”

  1. It’s not the white screen of death, but I have a single quote issue that’s fouling things up for me.

    On my site (http://www.runhundred.com) the search works fine–for the most part.

    But, if anyone searches for a post with an apostrophe (like Guess Who’s Coming To Dinner) the search not only fails to find the post, but also gets this error:

    Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource

    Any ideas on how to fix this?

    1. Hi Chris,

      That’s an interesting problem — the first thing I did was try a search term with an apostrophe on my own sites, but didn’t encounter any problems. However on your own site I noticed that according to the error message it is something in the search.php file on your site — this would be one of the files that your current theme uses — that has the problem with apostrophes.

      Have you tried reproducing the problem with a different theme? If you load a different theme — say the WordPress default, and you can’t reproduce the problem, then at least you’ll have narrowed down the cause considerably.

      Let me know what you find out; I’d be curious to know. And thanks for commenting.


Leave a Reply

Your email address will not be published. Required fields are marked *