Skip to content

WordPress and the Front Controller Design Pattern

Computer programmers love to think about systems. In doing that, they generalize how they work and how we can classify them. So you’ll find lots of people talking about “design patterns” — both loved and hated ones — that are common across the architecture of many different software systems.

One of my favorite patterns — having faced down more than a few legacy PHP apps that would have been much easier to change if they’d used it initially — is the Front Controller pattern. And WordPress uses it to powerful effect. Understanding the front controller pattern, how WordPress uses it, and what effect that has is really useful and helps you wrap your head around some other things about WordPress, so we’ll dive in.

What is the Front Controller Pattern?

Like a house with only one door, the front controller is the only way that people are allowed to talk to and get data from an application.

Put simply, the front controller pattern is observed in a system that only has one entry point. Like a house with only one door, the front controller is the only way that people are allowed to talk to and get data from an application. This pattern is popular on the web because it makes it easier to make good URLs (in the WordPress world we like to call that “pretty permalinks”) and saves us from repeating ourselves in many different scripts building up the same structure we need to use to respond to a web request (a request for data from our website).

Just for clarity, the “opposite” pattern to the front controller is the “page controller” which is actually how the administration section of WordPress is handled. In a page controller system, each thing that person might want is handled by a separate script or web page.

Yay! 🎉 You made it to the end of the article!
David Hayes
Share:

1 Comment
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Changing Your WordPress Theme from an External PHP Script | WPShout.com
February 18, 2014 5:33 pm

[…] this would only require one line of code. I knew it had to be pretty simple because WordPress uses the front controller design pattern, and so had to be “bootstrapping” — loading up — its functionality somewhere. I […]

Or start the conversation in our Facebook group for WordPress professionals. Find answers, share tips, and get help from other WordPress experts. Join now (it’s free)!