0

TL:DR; Is it possible to restrict page templates to a certain site within a multisite network? (Using something like get_current_blog_id for e.g)

More details

I’m building out several websites that each use the same base partials, just in different variations in their page templates. For e.g Site A & Site B’s home page both use Components A - D, however Site A’s goes A B C D and Site B’s goes C B A D. All my actual markup goes into the component partials and the page templates are mostly just a list of includes (using Roots Sage theme to help pass data).

This is the basic premise but we’re talking +-30 components and +-50 templates across 7 websites.

I’ve got all my templates in a subdirectory in my theme folder (e.g template-home-site-a, template-home-site-b) however this means when a user is working in the CMS for Site A they get a list of 50 templates, rather than just ones specific to Site A which might only be around 12.

Is there a way to possibly hook into Wordpress’ templating system and add/remove folders it looks in based on the current blog ID? Open to any other suggestions.

  • 3
    Hi Mikey! Welcome to the forum. While I could probably come up with a method to do what you are asking, your users would suffer very poor performance. Even caching could be a challenge. It would be far better to create child themes for each of your sites, with only the resources each requires. This reduce the number of calculations for drawing each page, resulting in faster load times. This also puts you ahead of the usual tweaks each site will require, while improving SEO. Good luck! – Mike Baxter Nov 12 '19 at 17:36
  • Hi @MikeBaxter Thanks for getting back to me. That sounds like it could be a good alternative, I’ll give it a bash tomorrow and see if I can get it working 100%. Cheers. – Mikey Nov 12 '19 at 17:44
  • Child themes are a superior solution. Always ask about the challenge you're facing not how to implement a solution to it. – Tom J Nowell Nov 12 '19 at 18:25
  • 1
    Also, if you had discrete components, why not make them blocks? Then you can rearrange them in the block editor on the page assigned to the homepage, no child themes or custom template folders or template files needed at all – Tom J Nowell Nov 12 '19 at 18:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.