If you ask any back-end programmers that has been accustomed to the use of frameworks with languages like PHP, Java, Ruby or Python to use WordPress to build a website, they will inevitably end up decrying it and most would prefer to avoid having to use any kind of CMS. The reality is that WordPress is a often considered a mess by most serious programmers as it was not made to follow clean programming rules but to allow non-programmers to launch a blog easily. It then evolved into something with a broader purpose when tons of plugins got developed for WordPress, which now allows to transform a WordPress website into pretty much anything. All these sometimes buggy plugins can each had their own mess to what can become a labyrinthine system.

What is WordPress?

All websites are built with the same technologies, those that run in the browser, which are HTML and CSS, the skeleton and styling of web pages. Many websites are actually static and directly built with those, other are dynamic and allow users to update their content through an admin panel, the content being saved in a database.

WordPress offers such an admin panel, it is a free and open-source content management system (CMS) based on the PHP programming language and MySQL database. The technologies it uses are simple and broadly available on most web servers, which makes it easy to install pretty much anywhere on the internet.

To paraphrase (supposedly) Churchill, though, “WordPress is the worst bogging system… except for all the others”, and there are reasons why WordPress is now powering 30% of all websites. and is reportedly the most popular website management or blogging system in use on the Web today, supporting more than 60 million websites.

Use cases for WordPress

At Outsourcify, we tend to think they are some cases when it makes sense to use WordPress and sometimes it’s better to use an alternative solution, most likely a custom developed web application. WordPress is a good choice when it at the same time simplifies the development of the website and the eases its update by its final users. The main reason to use WordPress is it’s user friendly admin panel that allows users to add and edit content easily, especially it’s well conceived Media Library.
Nearly any website or web application concept could be built with WordPress as the CMS (Content Management System) but from the moment some of the requirements would require to create enormous plugins or hack existing plugins, WordPress is to be avoided.

WordPress is fit for corporate websites displaying pages, articles and any kind of content that can be displayed through the same page templates. With the help of WooCommerce, online shops, if they keep to the usual features of classic e-commerce, can also be created effectively with WordPress, and much cheaper and with a custom solution.

MVC development with WordPress

Now in any case, if WordPress is chosen, there are some ways to improve WordPress that here at Outsourcify we consider to be mandatory, the first one is bring the Model–view–controller (MVC) architectural pattern to WordPress simply by separating the controllers (PHP scripts) from the view (templates) and add features to allow to update the data model. It’s as simple as installing 2 plugins : Timber and ACF.

Timber providing the Twig templating engine

WordPress still doesn’t come with any templating system after all those years (it was created in 2003!), it means PHP code is intertwined with HTML, which considered bad programming for a reason. As a WordPress custom theme builder, our priority at Outsourcify is to fix this and it happens that there is a plugin to add templating to WordPress : Timber. The fact Timber introduces the Twig templating engine can only satisfy us as it is maintained by the team behind the Symfony, our PHP framework of choice when we code custom web applications.

The official WordPress theme development recommendations and the themes provided with WordPress (Twenty Ten, Twenty Eleven, Twenty Twelve) offer to get and display information in the same files. They don’t encourage separating core site functionalities to a plugin. So what you usually end up doing are cryptic loop constructions and a gigantic functions.php file. Timber brings some development principles from the Model–view–controller (MVC) architectural pattern to WordPress simply by separating the controllers (PHP scripts) from the view (Twig templates). It’s as simple as installing the plugin to make your custom themes much cleaner.

A real CMS with custom posts and ACF (Advanced Custom Fields)

The “Model” in MVC stands for data as in database, how the information is stored connected together. WordPress offers by default blog entries and pages as it is originally a blogging system. To add new data types in WordPress we use custom posts, which are called entities or objects in other programming systems. Custom posts are not enough as they are basically copies of the blog entry, with the same basic fields : title, content, author etc.

The ACF plugin allows to add other types of fields to our entities : text, images, urls, links, whatever information is needed to defined an entity. The free version of ACF is enough for most cases but it should be noted that the PRO version gives a few very useful additional data types, the “repeater”, “gallery” or “flexible content” fields are a must.

It’s not the purpose of this article to explain in details how to use both of these plugins, you can easily find tutorials on how to use them, the best being to start with their documentation :

By using some of the principles of the MVC design pattern, we’re not saying WordPress now becomes a full fledged MVC framework, but it’s getting closer to it, WP theme developers can now center around each concern each one by one – defining the information in the model, data retrieval and processing in the controllers, and lastly displaying the data in the templates. Separating these 3 different concerns makes development much more quicker, adaptable, maintainable and most of all fun.