You would need to write a custom theme. You can then automate that bit in the layout page(s). It's not as bad as it sounds as new themes can inherit from a parent - you only need to code some boilerplate and the bits that are different.
https://docs.moodle.org/dev/Themes
https://docs.moodle.org/dev/Themes