WordPress Theme Architecture — How To Implement Theme Features Without Bloat

Wordpress-architecture

I’ve seen a lot of rants from WordPress users and some developers wherein they put their wisdom hats and call themes a bloated one or a slick simple ideal theme. And a general belief is that a bloated theme is bad and a simple theme is the way to go. However this is not a universal truth. There are times when a full featured theme does the job without being bloated.

What is a theme?

A theme is just a couple of templates that display the content stored in the WordPress database as per the defined view. Nothing more, nothing less. WordPress sites can’t work without a theme.

What is a plugin?

A plugin is a piece of software that extends the WordPress functionality in some way. This could be the core WordPress functionality, extending the functionality of another plugin or even the theme itself.

In the last few years the themes have evolved beyond their basic definition. The reasons are manifold. Let’s see why do we use themes.

We use themes to serve a specific purpose. Perhaps a specific aesthetic that is mandated by the site or the user experience. However be it themes or plugins, they are just a means to an end. Even WordPress itself is the means to an end. And that end is the website. All the various components need to be configured and made to play together so that they eventually result in a successful website.

The premium theme market has grown to address this very need — to allow the users to build a successful website. And a successful website isn’t a result of a minimalist theme. The aesthetics and functionality are the two building blocks of a successful website and are often intertwined to make things work for the common shared goal.

Themes must be seen as a solution

WordPress themes in this particular application can’t be seen as a bare minimum component. They are a part of the larger solution and a solution in their own right. When we differentiate between theme functionality and the plugin territory, we do it in order to ensure that a theme stays specific to its purpose. But with niche specific themes the argument falls flat on its face because there you need to achieve a particular functionality with or without a theme. Let me cite you an example:

Business websites typically will have at least one landing page. It’s something that the site mandates regardless of whether you implement it via a theme or a plugin. In this regard niche specific themes have to step into the plugin territory to ensure that the complete solution to a problem is delivered instead of a half baked solution that has plugin dependencies.

The challenges with this approach

The primary challenge with the above approach is the dependence of the website on a particular theme to achieve the specific purpose. The moment you change the theme the site functionality breaks.

The second challenge is that all the code required to implement these features is a part of the site whether it’s used or not.

The solution

A smart choice is to give the power to the site-developer/designer. The right way to implement these additional features is to do it without bloating the theme. And WordPress addresses this very issue with the require_if_theme_supports function calls.

The right way to implement the features in the theme is not to hard-code them but to have them ready to come into action with the add_theme_support call. The moment the support for that feature is declared, your feature-specific code should be called into action via the require_if_theme_supports function call. There are several other siblings of this call viz. the post_type_supports etc.

In the last several day I’ve seem some of us who declare a theme as bloated based on theme size (yes, the file size of the entire theme!). Others use the ‘bloat’ word because the pros use it and it makes them sound like a seasoned coder.

WordPress theme requirements are not incorrect

WordPress theme requirements in this regard may seem rudimentary. However it’s not intelligent to take things at face value.

Themes in the WordPress directory are generic themes that must work with any standard installation of WordPress. As such it becomes critical for the official showcase of WordPress themes to only allow themes that adhere to the larger WordPress ecosystem and play well with everything else without breaking the installation, slowing things down or overriding plugin functionality or any unwanted interference that is not expected of a theme. And as long as you are building a generic theme for the larger WordPress market your theme must by all means ensure that it plays well within the WordPress ecosystem.

However when it comes to implementing functionality in the theme itself, it’s mostly done to build a larger solution without any third party dependencies. In such cases the right choice is to only call the code when support for a feature is specifically declared. This will let the theme work optimally without bloat. And the next time you find someone declare a theme as bloated because of file-size or a specific feature, disseminate, dissect and study the feature implementation in the theme yourself. You are buying a premium theme. There’s no excuse for sluggishness, but don’t settle for anything that doesn’t rightfully solve the purpose and challenges of your business website. Your website needs it either-ways whether in the form of a theme or a plugin and ultimately you deserve to get the value of every penny you spend.

Divi WordPress Theme