Writing a Wordpress theme in less than 4kb
![Logo for Cellula, a wordpress theme](/content/images/size/w960/2024/06/screenshot.png)
Some weeks ago my attention was caught by an interesting and strikingly original feat accomplished by Terence Eden with a blog post titled “A completely plaintext Wordpress theme”: In short, the author was able to condense the basic output of a Wordpress classic theme in less than 15 lines of code, generating a simple but effective text-only blog; It was especially interesting observing how Wordpress was still able to chug along and print out the main contents of a post despite missing the most of what is considered the bare minimum to actually init the CMS without getting any error, let alone rendering and displaying any article.
This wasn't the first time I’ve heard of similar experimental projects within the Wordpress community; Despite of all its limitations, the classic theme format structure makes for a rather immediate platform for building similar offbeat projects. For example, let’s take a look at another work in the "less-is-more" category, named Susty: written by Jack Lenox, this theme tries to output the smallest page possible in order to reduce the carbon offprint of the content, keeping the payload to under 7kb. It's a cleverly written theme, taking in consideration some issues (like additional power consumption by using multiple CDNs or the readability on low brightness displays of the overall design) usually ignored in most commercially-deployed theming solutions.
So, you may be wondering, where am I going with this? I’ll preface I’m nowhere near that smart to attempt writing anything comparable to the previous two projects, but taking the previously aforementioned themes as inspiration I've written Cellula: a full fledged Wordpress theme consisting of a single .php file weighting 3.218 bytes in size (plus the mandatory, nearly empty 350 bytes style.css). It supports comments, widgets and archives.
Please, consider Cellula just a proof of concept, as I wouldn’t recommend using it as your theme for any serious project. Still, there’s a lot to be drawn from a project like this. I was quite surprised to see that both widgets and comments required little if absolutely no customization from their respective builtin core calls to be integrated in a theme, or by how little CSS is actually required to give a decent appearance to a mostly-textual web page (widely confirming what http://bettermother***ingwebsite.com has always stood for in its expletive ridden tirade). Most Wordpress features should work with little to no issues, even default Gutenberg blocks should render correctly.
Unfortunately, by the virtue (?) of not having a functions.php file it means I cannot implement any hooks, actions or filters during the initialisation part of the rendering loop. In practice though it only affects the copyright text in the footer, given that there is no way to add custom fields or additional widgets areas.
The minified code is available on github here; simply download the zip file and install like a regular Wordpress theme.