# SEO optimization: how to force \`#\` to generate h2, and so on?

**URL:** <https://discourse.gohugo.io/t/seo-optimization-how-to-force-to-generate-h2-and-so-on/49597>\
**Category:** support\
**Created:** [May 2, 2024, 3:59pm UTC](https://discourse.gohugo.io/t/seo-optimization-how-to-force-to-generate-h2-and-so-on/49597 "2024-05-02T15:59:13Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![wrobelda](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/wrobelda/32/21925_2.png) [@wrobelda](https://discourse.gohugo.io/u/wrobelda)\
**Post date:** [May 2, 2024, 3:59pm UTC](https://discourse.gohugo.io/t/seo-optimization-how-to-force-to-generate-h2-and-so-on/49597/1 "2024-05-02T15:59:13Z")

</div>

For SEO optimization, it is said that only a single H1 heading should be present on the page, and most of the themes already default to using it for the post’s title.

Is there a way to configure markdown parser to treat a single hash (`#`) as a h2 heading, and so on? Obviously I can simply resort to using double `##` headings, but I am afraid I’ll forget sometime down the line.

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [May 2, 2024, 4:05pm UTC](https://discourse.gohugo.io/t/seo-optimization-how-to-force-to-generate-h2-and-so-on/49597/2 "2024-05-02T16:05:55Z")

</div>

> [@wrobelda](#):
>
> Is there a way to configure markdown parser to treat a single hash (`#`) as a h2 heading

No.

The content below the front matter should never contain a level 1 heading. If you’re afraid you’ll forget, add it to the archetype(s) content.

---

<div class="post-metadata">

**Author:** ![wrobelda](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/wrobelda/32/21925_2.png) [@wrobelda](https://discourse.gohugo.io/u/wrobelda)\
**Post date:** [May 2, 2024, 4:27pm UTC](https://discourse.gohugo.io/t/seo-optimization-how-to-force-to-generate-h2-and-so-on/49597/3 "2024-05-02T16:27:15Z")

</div>

> [@jmooring](#):
>
> The content below the front matter should never contain a level 1 heading.

This isn’t too obvious until you actually read into SEO optimization. And if the content below the front matter should never contain a level 1 heading, then why even make it possible? Wouldn’t it make sense to have Hugo automatically generate h2 headings by default, possibly exposing this as an option?

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [May 2, 2024, 4:29pm UTC](https://discourse.gohugo.io/t/seo-optimization-how-to-force-to-generate-h2-and-so-on/49597/4 "2024-05-02T16:29:57Z")

</div>

> [@wrobelda](#):
>
> Wouldn’t it make sense to have Hugo automatically generate h2 headings by default, possibly exposing this as an option?

Because maybe you don’t want to have the H1 title in a template, but instead in content.

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [May 2, 2024, 4:35pm UTC](https://discourse.gohugo.io/t/seo-optimization-how-to-force-to-generate-h2-and-so-on/49597/5 "2024-05-02T16:35:54Z")

</div>

If you feel strongly about this I supposed you could create a heading render hook that adds 1, but then your rendered Markdown will not conform to either the [CommonMark](https://spec.commonmark.org/0.31.2/#atx-headings) or GitHub Flavored Markdown specification.

---

<div class="post-metadata">

**Author:** ![wrobelda](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/wrobelda/32/21925_2.png) [@wrobelda](https://discourse.gohugo.io/u/wrobelda)\
**Post date:** [May 2, 2024, 4:46pm UTC](https://discourse.gohugo.io/t/seo-optimization-how-to-force-to-generate-h2-and-so-on/49597/6 "2024-05-02T16:46:07Z")

</div>

I just realized that even if I do remember about limiting h1 usage myself, I have a comments section on my website where markdown is accepted as well. So any `#`s there will inevitably end up in making that page non-conformant to SEO rules.

I believe this is a bigger issue than it appears to be and a systemic solution to this would be worth looking into.

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [May 2, 2024, 4:48pm UTC](https://discourse.gohugo.io/t/seo-optimization-how-to-force-to-generate-h2-and-so-on/49597/7 "2024-05-02T16:48:27Z")

</div>

> [@wrobelda](#):
>
> systemic solution

See my previous reply, but you’re on your own regarding whichever commenting system you’ve integrated.

---

<div class="post-metadata">

**Author:** ![xuhdev](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/xuhdev/32/21739_2.png) [@xuhdev](https://discourse.gohugo.io/u/xuhdev)\
**Post date:** [May 3, 2024, 2:35am UTC](https://discourse.gohugo.io/t/seo-optimization-how-to-force-to-generate-h2-and-so-on/49597/8 "2024-05-03T02:35:23Z")

</div>

This sounds like better addressed by a linter, not hugo (the “compiler”).

`markdownlint` has a rule that performs exactly what you need:

> <https://github.com/DavidAnson/markdownlint/blob/v0.32.1/doc/md025.md>

It detects whether there’s a title in the frontmatter. If so, it would report `h1` in the body as an error. If there’s no title in the frontmatter, it detects whether the body contains no more than 1 `h1`.

---

<div class="post-metadata">

**Author:** ![wrobelda](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/wrobelda/32/21925_2.png) [@wrobelda](https://discourse.gohugo.io/u/wrobelda)\
**Post date:** [May 3, 2024, 4:10pm UTC](https://discourse.gohugo.io/t/seo-optimization-how-to-force-to-generate-h2-and-so-on/49597/9 "2024-05-03T16:10:39Z")

</div>

This is brilliant and indeed makes more sense in this case. Thank you!

---

<div class="post-metadata">

**Author:** ![system](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/system/32/1_2.png) [@system](https://discourse.gohugo.io/u/system)\
**Post date:** [May 5, 2024, 4:11pm UTC](https://discourse.gohugo.io/t/seo-optimization-how-to-force-to-generate-h2-and-so-on/49597/10 "2024-05-05T16:11:12Z")

</div>

Closed on May 5, 2024, 4:11pm UTC

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