I am trying to build an install profile and I want to have my custom theme enabled and set by default after the installation.

Adding in MYPROFILE.info.yml...

  - my_theme

...is not enough. This only installs it, but it is not set as the default theme.

I guess I have to do something else in the MYPROFILE.install file in

function MYPROFILE_install() {
  // how to set as default my custom theme

Thank you

2 Answers 2


Looking at ThemeController::setDefaultTheme (the request handler for the /admin/appearance/default route), this should do the trick:

  ->set('default', 'machine_name')
  • For this to work, theme must be already enabled. Still don't know how to enable it programmatically.
    – dxvargas
    Feb 11, 2017 at 12:12
  • 3
    @hiphip Fortunately that's quite straightforward: \Drupal::service('theme_installer')->install(['theme_name']);
    – Clive
    Feb 11, 2017 at 12:16

You can create a site that has the correct default theme, and copy over the theme related config files into your profile's config directory (or all the files if it makes sense for your profile).

See https://www.drupal.org/node/2210443#config for more.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.