# 是否可以在一个地方全局编辑\<header\>？

**URL:** <https://meta.discourse.org/t/is-there-a-way-to-edit-header-site-wide-in-one-place/148528>\
**Category:** Support\
**Created:** [2020年四月19日 14:54 UTC](https://meta.discourse.org/t/is-there-a-way-to-edit-header-site-wide-in-one-place/148528 "2020-04-19T14:54:26Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![007](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/007/32/175794_2.png) [@007](https://meta.discourse.org/u/007)\
**Post date:** [2020年四月19日 14:54 UTC](https://meta.discourse.org/t/is-there-a-way-to-edit-header-site-wide-in-one-place/148528/1 "2020-04-19T14:54:26Z")

</div>

你好，我注意到可以在每个主题中单独编辑页眉，但是否有一种方法可以在一个地方进行全站范围的编辑？

比如添加 Facebook 像素、Google Tag Manager 等。我知道有 Google Tag Manager 插件，但就这个问题而言，我更关注的是如何通用编辑页眉以及相关的最佳实践。

谢谢！

---

<div class="post-metadata">

**Author:** ![Canapin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/canapin/32/119591_2.png) [@Canapin](https://meta.discourse.org/u/Canapin)\
**Post date:** [2020年四月19日 15:16 UTC](https://meta.discourse.org/t/is-there-a-way-to-edit-header-site-wide-in-one-place/148528/2 "2020-04-19T15:16:07Z")

</div>

除非我误解了您的请求，否则您可以创建自己的主题组件并将其添加到所有主题中。

---

<div class="post-metadata">

**Author:** ![007](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/007/32/175794_2.png) [@007](https://meta.discourse.org/u/007)\
**Post date:** [2020年四月19日 15:49 UTC](https://meta.discourse.org/t/is-there-a-way-to-edit-header-site-wide-in-one-place/148528/3 "2020-04-19T15:49:39Z")

</div>

也许我提问的方式不对，但据我所知，除了修改模板外，编辑页眉的唯一位置就在这里：

 ![image](https://global.discourse-cdn.com/meta/original/3X/9/6/963e43e4a008ac56d392239d14b61aa5dda2c0b2.jpeg)

但我基本上需要在每个主题中手动编辑页眉。如果一个网站有几十个主题，这会变得很繁琐。

我想知道是否有更好的方法可以全局编辑页眉，这样我只需要操作一次即可。

---

<div class="post-metadata">

**Author:** ![Canapin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/canapin/32/119591_2.png) [@Canapin](https://meta.discourse.org/u/Canapin)\
**Post date:** [2020年四月19日 16:02 UTC](https://meta.discourse.org/t/is-there-a-way-to-edit-header-site-wide-in-one-place/148528/4 "2020-04-19T16:02:00Z")

</div>

所以我的建议是可行的路径。  
在“自定义”中，进入“组件”，创建一个新的主题组件，编辑其 `<head>` 内容，然后在组件设置中将其添加到所有主题中。

---

<div class="post-metadata">

**Author:** ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)\
**Post date:** [2020年四月19日 16:20 UTC](https://meta.discourse.org/t/is-there-a-way-to-edit-header-site-wide-in-one-place/148528/5 "2020-04-19T16:20:42Z")

</div>

> [@007](#):
>
> 如果一个网站有几十个主题，管理起来会变得繁琐。

创建一个主题组件。您可以一键将其添加到所有主题中。

---

<div class="post-metadata">

**Author:** ![007](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/007/32/175794_2.png) [@007](https://meta.discourse.org/u/007)\
**Post date:** [2020年四月19日 17:15 UTC](https://meta.discourse.org/t/is-there-a-way-to-edit-header-site-wide-in-one-place/148528/6 "2020-04-19T17:15:20Z")

</div>

感谢 @Canapin 和 @pfaffman。我没想到这竟然可行。这轻松解决了我遇到的问题！

---

<div class="post-metadata">

**Author:** ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)\
**Post date:** [2020年五月19日 17:15 UTC](https://meta.discourse.org/t/is-there-a-way-to-edit-header-site-wide-in-one-place/148528/7 "2020-05-19T17:15:23Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
