How to simplify a complicated WordPress multisite install, and make it futureproof?


Lately I have been included in a larger WordPress based project as a font-end developer. The one of the biggest customer on Malta have ordered 13 websites, all must have to be a member of a multisite installation. I joined the group approximately at the 40% of the full project being finished.

Although the sites could be grouped by design, there were no parent-child themes in use at that time. As the project grew before I have joined the group it was already way too complicated to be ignored.

Before we would move on with the development to the next group of websites, we paused a little, and had a clean-up. We restructured the old sites and made a plan for the new ones as well.

At first, we categorized the existing files

  • Identical: These are the files which should be in the parent theme folder as they are exactly the same for all websites
  • Not identical, but can be: These are the files which main part can be generalized and just contains a small part that is unique for that specific website
  • Not used: These are the files which became irrelevant as the development went further
  • Files could be combined: These are the files which were separated for no special reason. These could be combined and have the same functionality as the separated files had before, thanks to the conditional tags in WordPress.
  • Unique: These are the files which should be in the child theme folder as they give an extra functionality for one website only. For example, a unique home page.

We had approximately 60-80 PHP files per website, which does not sound a lot, but keep in mind that we are talking about five websites in one group, and we also knew we have to create new groups as well. 15-20 unnecessary files multiplied by 5 gives you 75-100 extra files you have to take care of.

We did not just take care of PHP files, but every other common files as well. And other than that, we also realized how many things have in common not just in one group, but between groups. We needed a higher level of sharing than the parent theme folder structure.

Presentation about the clean-up process

New Libraries

We created a Library folder above the default themes folder in WordPress, with two subfolders, one is for common PHP files, and one for common LESS files. As every site based on Bootstrap (what we have modified for our needs) and there are a lot of structural similarities in parts of WordPress as well, our LESS compilations include these common LESS files from the same Library.

Wordpress Multisite structure with extended libraries

WordPress Multisite structure with extended libraries

We do not have 13 copies of the modified Bootstrap LESS files, neither have the very same WordPress CSS coding for simple modules like comment boxes, image alignments, basic hack and we also create some plug-in specific LESS file. We combined every structural coding in our Library, so we have to deal with the colouring and the unique codes in the child themes or parent themes folders only.

In our PHP Library we have some custom-made widgets, and code snippets which are cam be included at any point of any of the 13 websites.

Wordpress Multisite structure with extended libraries

WordPress Multisite structure with extended libraries

Meanwhile I created a map of files and their connection with Xmind, one of my favourite software. This map is very useful to keep the track of changes. I color-coded the different file types, and in the original version I also kept everything what have been deleted. On the map we have documented not just the files, but custom taxonomies, custom fields, and functions as well.

At the end of the clean-up process the number of files was less with more than 30%, which means we were able to make bug fixing and do the further development way faster. We also gained speed on creating new websites in this multisite install, and at the end we were able to finish the full project with two months earlier as planned.