Using same theme over multiple sites, using a config to control differences

I currently Have 3 websites built and running on production using Sage. They are pretty much the same site, apart from some minor styling (fonts, colours etc). The main content differences are controlled in WP.

I’ve tweaked some functionality using a .env value to control which main scss file is complied (each just calls a different variables.scss file)

if (getenv('WP_SITENAME') == 'site1') {
    wp_enqueue_style('sage/site1__main.css', asset_path('styles/site1__main.css'), false, null);
    wp_enqueue_script('sage/site1__main.js', asset_path('scripts/site1__main.js'), ['jquery'], null, true);
} else {
    wp_enqueue_style('sage/site2__main.css', asset_path('styles/site2__main.css'), false, null);
    wp_enqueue_script('sage/site2__main.js', asset_path('scripts/site2__main.js'), ['jquery'], null, true);
}

However I’d like to give some configurability within the HTML as well. Something like a config file somewhere that gives the different sites some configurability.

The getConfig() function would probably be in a controller, and would return the appropriate config object, depending on the same WP_SITENAME from the .env .

However I don’t know where to put the config file/data, or how best to access it. It seems super messy to just have it in the controller.

Should I put it in /myThemeName/config? And then should it be a new file or an existing one?

This topic was automatically closed after 42 days. New replies are no longer allowed.