Headless WordPress Is A Joke

Jason Ching
5 min readJan 19, 2021

Today, I come to know there is such a thing call Headless WordPress. After I realize what this really is about, seriously, I laughed. Oh man, this is just so wrong.

I first have to admit that I have bias of making technology selection. Anyway, all developers should have bias on something. I am going to explain my view on this in a reasonable way. The reason of writing this article is to convince everybody to stay away from this idea, before you start. This is a dead end. Please just don’t go there.

So, what is Headless WordPress?

There are some people using the term Model-View-Controller and Decoupling to explain this. They are not wrong, but just too complicated and not exactly accurate.

Here is my way of explanation:

Simply put, your WordPress will now just being requested as a web service. The response is in json format. And you are going to use JavaScript to do the render in the browser. This takes place in client’s machine, not the server.

What people are thinking…

There are few reasons people are excited about (and already jumped into) this:

  • It’s faster. Without letting the PHP to render the HTML, the server has less overhead. And the rendering computation power is off loaded to the client’s browser (mobile or desktop). That definitely will give better experience to the user.
  • Separation of concern. Now your WordPress will only handle data. No more messy presentation concern. It makes WordPress a pure CMS layer.
  • Better integration to anything. This infrastructure can be extended to some applications that is not web based. May be some IoT, some application integrates with other application. It opens up a whole new possibilities for WordPress.

There are a lot more benefits I can write about, but I am going to stop here. This is not really the point of this article.

Okay! So, I am not denying any of the above benefits. They are all very valid. In fact, this is not something new. This is just a simple three tier architecture (Front end, Service Tier, Database) exists for years. May be this is new in WordPress, but definitely not in the development world. The real question we have to ask is:

Why do we still need WordPress in this architecture?

No more hooks in headless!

The best part of WordPress is hooks! Or I should say, the only good thing about WordPress is hooks! Nothing else!

Don’t get me wrong. I don’t really hate WordPress. I have been using it to build countless website and eCommerce. Using WordPress wisely can be a very cost and effective way to deliver. All these benefits come from hooks.

So let’s dive deep now.

PHP is a template script!

PHP is built as a sole purpose of template script. See how it’s creator, Rasmus Lerdorf, had explained it.

We end up making it a full bone web server to delivery HTML content. Which is something we didn’t expected, but that’s fine. But now we are going a step further: just to keep PHP as a server API with no HTML stuff!

Oh I just don’t understand how we get to this part. The strength of PHP is to dump HTML to the HTTP response. You can just put a <?php tag to make the magic happen. Now we stop using this? And we are using it as a API service? This is the weakest of PHP!

Node.JS is a lot faster in Server

There is no way PHP can be a better API service than Node.JS.

JavaScript was originally just a script program in the browser It was also an insane idea to port it to server side. But we saw the huge benefit in the first day: Concurrency!

Node.JS handles concurrency using event loop architecture. PHP handles it by using thread. We can end this discussion here. The way Node.JS do it (with better programming syntax and it’s event loop backbone) is for sure the winner. (Same reason why NGINX is faster than Apache).

Not to mention that JavaScript has better syntax sugar to handle asynchronous call.

So, my question is, why the heck would I use PHP in my service layer?

WordPress is not a good CMS backend

Now we talk about the database structure.

First of all, it’s not difficult to build a similar CMS like WordPress from scratch.

WordPress’s database is way too simple and generic. It basically just put everything into the post table. Even attachment is a post record there. Then we have a post_meta table which gives a one-to-many key-value pair collection to the post record.

This is a very simple data structure and it’s very easy to build from scratch. If you love it, you can do it in Node.JS. That’s shouldn’t be the reason why you need to stick with WordPress with tons of other overhead and constraint.

This is flexible, but may not be a good data structure in lots of cases. First of all, it’s slow by design. (The price you pay for flexibility). I just can’t agree this is a good advantage in WordPress.

Hooks is dead in Headless WordPress

Most of the hooks in WordPress is actually just manipulating the response HTML.

For example, I wanna add an extra field in the WooCommerce checkout. I wanna hook in a js script in the page header. That’s the good part of WordPress.

I can do those with just few lines of code without touching the WordPress Core. Now these are all gone.

Now we have nothing left

Now we abandon our hooks. We left with PHP and a totally restricted database. (Yes, I know you can tell. I hate PHP. Seriously, you should use Laravel if you really want to stick with PHP) (Putting everything into one place, the post, is not a good design). These just not making any sense here.

Scalability?

You may thing that such new headless architecture gives better scalability to your site.

By scalability I mean your system can grow. You can handle huge traffic across the border, something like that.

But this gives you nothing close to NOSQL database like MongoDB. Mysql just can’t scale like that. So if scalability is your goal, you should ask yourself what WordPress can really give you.

WordPress is for simple things

Don’t over complicated it. For company intro site, eCommerce, blogging, WordPress is good! But don’t use it to build a complicated system. This is obviously not a good choice of your back end server.

Traditional finance and banking corporate uses Oracle and Java. New corporate like social media uses NOSQL with python, NodeJS stuff. Instant messenger application uses messaging queue like RabbitMQ. These are real robust and scalable tools for specific purpose. PHP with WordPress comes no where near them.

On the other hand, hooks is really great. I haven’t seen any other applications can provide something flexible like hooks in WordPress. Different tools for different things. Don’t try to extend it to something you are not supposed to and you end up losing your own strength.

--

--