Set Theme Dynamically

Sorry for the long wait. Busy day :technologist:

So, you can indeed enable or disable a theme or a component with a simple API request.

You’ll have to create an API key with the right credentials and assign an admin user to it.

  • in your Discourse: admin panel → API → + New API Key

  • in the script you’ll use, as mentioned, do a PUT request on https://yourdiscourse.com/admin/themes/[id_theme] with the proper headers (see the authentication part on https://docs.discourse.org/) and a JSON body such as:

    {"theme":{"enabled":false}}
    

This will disable the chosen theme/component. Video example with Insomnia:

1 Like