# 404-solution/4.2.0/includes/html/themeSetterScript.html

404 Solution, version 4.2.0. 20 lines.

- Page: https://pluginprobe.com/plugins/404-solution/4.2.0/code/includes/html/themeSetterScript.html
- Raw: https://pluginprobe.com/plugins/404-solution/4.2.0/raw/includes/html/themeSetterScript.html
- Modified: 2025-11-20T14:18:22+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/404-solution/4.2.0/code/includes/html/themeSetterScript.html#L10-L20`.

```html
<script type="text/javascript">
(function() {
  // Apply theme synchronously to html element to prevent FOUC
  // This runs immediately when the script executes in <head>, before body is parsed
  document.documentElement.setAttribute("data-theme", "{theme}");

  // Also apply to body for redundancy (ensures both html and body have the attribute)
  if (document.body) {
    document.body.setAttribute("data-theme", "{theme}");
  } else {
    // If body not available yet, set it when DOM is ready
    document.addEventListener("DOMContentLoaded", function() {
      if (document.body) {
        document.body.setAttribute("data-theme", "{theme}");
      }
    });
  }
})();
</script>

```
