Overriding the admin theme is easy, but no one seems to talk about it. Let's change that here.

Almost everything in Orchard is achieved by implementing an interface. Orchard will collect all the implementations and loop through them, or it selects the one with the highest priority; depending on the feature.

Good news everybody, it's the same for overriding themes!

TLDR;

  • Implement IThemeSelector
  • Make sure you check the AdminFilter
  • Return a ThemeSelectorResult with a higher priority than the default admin theme.
  • Activate your custom admin theme. (Do not click Set current)
namespace MyAwesomeAdminTheme
{
    using System.Web.Routing;

    using Orchard.Themes;
    using Orchard.UI.Admin;

    public class OverrideTheAdmin : IThemeSelector
    {
        public ThemeSelectorResult GetTheme(RequestContext context)
        {
            if ( AdminFilter.IsApplied(context) )
            {
                return new ThemeSelectorResult
                {
                  Priority = 110,
                  ThemeName = "MyAwesomeAdminTheme"
                };
            }

            return null;
        }
    }
}

And that's about it, from here on it's customizing as usual.

How it works

This section shines a little light on the code above. If you've got some time and want to know what you're doing (I hope you do), this is for you.

To get a list of all implementations of a certain interface, simply inject it as IEnumberable<ISomeInterface> and autofac will take care of the rest.

So on every request that returns a themed result, Orchard will collect all IThemeSelector implementations, including your new admin theme selector. Because of this, it's important to check that the current route is actually the admin dashboard by calling AdminFilter.IsApplied. Otherwise you would also override your active frontend themes.

It will then order them by priority (highest first), and take the first active theme that matches the name of the current ThemeSelectorResult. The result is assigned as current theme to the current request.

Happy coding!


Fun fact

For some reason there are two identical implementations of the GetRequestTheme function. One in Orchard.Themes/Services/ThemeService.cs the other in Orchard/Themes/ThemeManager.cs.