Drupal 7 – Enable a theme from a custom module via code

Sometimes you are required to enable a theme programmatically from a module without needing to do it manually all the time, so to do this I have used the hook_init() function to get a list of all the themes in Drupal which contains all the themes info.

Then I am using the name of the theme (the one in the .info file) and after checking if the status is disabled I call themeenable function and pass an array with the theme name I want to enable. The themeenable function accepts an array of theme names, so you are able to enable multiple themes at once.