# 将 CurrentThemeId 添加到 Body CSS 类中

**URL:** https://meta.discourse.org/t/add-currentthemeid-into-body-css-classes/161380
**Category:** Support
**Created:** [2020 年8 月 19 日 14:52 UTC](https://meta.discourse.org/t/add-currentthemeid-into-body-css-classes/161380 "2020-08-19T14:52:37Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![awesomerobot](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/awesomerobot/32/142900_2.png) [@awesomerobot](https://meta.discourse.org/u/awesomerobot)
#### Post date: [2020 年8 月 20 日 02:47 UTC](https://meta.discourse.org/t/add-currentthemeid-into-body-css-classes/161380/2 "2020-08-20T02:47:20Z")

</div>

我们不使用名称作为 ID，只使用数字。你可以在管理员面板中自定义主题时查看 URL 来获取主题的 ID，例如 `https://forum.example.com/admin/customize/themes/140`。

如果你可以使用 ID 而无需名称，这是一种快速实现方法（将其添加到你的主题/组件的 head 文件中）：

```xml
<script type="text/discourse-plugin" version="0.8">
  var themeSelector = require('discourse/lib/theme-selector');
  document.querySelector("body").classList.add("theme-id-" + themeSelector.currentThemeId())
</script>

```

你也可以通过 ID 查找主题名称，但这需要更多的工作。

---

_[View the full topic](https://meta.discourse.org/t/add-currentthemeid-into-body-css-classes/161380)._
