# Adding comments in a blog post in a way that it is not added to the generated HTML

**URL:** <https://discourse.gohugo.io/t/adding-comments-in-a-blog-post-in-a-way-that-it-is-not-added-to-the-generated-html/52677>\
**Category:** support\
**Created:** [December 7, 2024, 11:31am UTC](https://discourse.gohugo.io/t/adding-comments-in-a-blog-post-in-a-way-that-it-is-not-added-to-the-generated-html/52677 "2024-12-07T11:31:28Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bjoern](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bjoern/32/4245_2.png) [@bjoern](https://discourse.gohugo.io/u/bjoern)\
**Post date:** [December 7, 2024, 11:31am UTC](https://discourse.gohugo.io/t/adding-comments-in-a-blog-post-in-a-way-that-it-is-not-added-to-the-generated-html/52677/1 "2024-12-07T11:31:28Z")

</div>

When I write content for a page I have sometimes multiple ideas how to write it down. Usually I use the HTML comment syntax (`<!-- some content -->`)to hide stuff I don’t want to have on the webpage. This works in general great, with one small drawback. If someone looks at the source code of the webpage they will see the multiple versions of the paragraph and search engines might index it as well.

Is there a way to comment stuff out in a .md file in a way that Hugo will ignore it completely while generating the html pages?

---

<div class="post-metadata">

**Author:** ![davidsneighbour](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/davidsneighbour/32/24507_2.png) [@davidsneighbour](https://discourse.gohugo.io/u/davidsneighbour)\
**Post date:** [December 7, 2024, 11:37am UTC](https://discourse.gohugo.io/t/adding-comments-in-a-blog-post-in-a-way-that-it-is-not-added-to-the-generated-html/52677/2 "2024-12-07T11:37:32Z")

</div>

If those comments stay in the resulting output then you have disabled “safe HTML” somewhere in your options, because typically GoHugo would strip out all HTML tags. If that is not an option for you (at least give it a thought) then my advise would be to use a shortcode that returns one single space and use the stuff between the shortcode’s opening and closing tag as your comment.

Inside of template files you can always `{{/* comment out stuff */}}`, but I assume we are talking about content files here.

---

<div class="post-metadata">

**Author:** ![davidsneighbour](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/davidsneighbour/32/24507_2.png) [@davidsneighbour](https://discourse.gohugo.io/u/davidsneighbour)\
**Post date:** [December 7, 2024, 11:39am UTC](https://discourse.gohugo.io/t/adding-comments-in-a-blog-post-in-a-way-that-it-is-not-added-to-the-generated-html/52677/3 "2024-12-07T11:39:13Z")

</div>

```markdown
{{< comments >}}
My comments here
{{< /comments >}}

```

and in layouts/partials/comments.html:

```html
{{ $something := .Inner }}
&nbsp;

```

You need to at least “load” the `.Inner` or GoHugo will throw an error. And you need to return something or GoHugo will throw an error (I think, might have changed over time).  
Not tested.

---

<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:** [December 7, 2024, 5:42pm UTC](https://discourse.gohugo.io/t/adding-comments-in-a-blog-post-in-a-way-that-it-is-not-added-to-the-generated-html/52677/4 "2024-12-07T17:42:08Z")

</div>

In its default configuration, Hugo [removes HTML comments](https://gohugo.io/getting-started/configuration/#configure-minify) from the published page when you build your site with the `--minify` flag.

With v0.137.1 and later, use the the [comment shortcode](https://gohugo.io/content-management/shortcodes/#comment) to add comments to the body of your Markdown. You can learn more about this change [here](https://discourse.gohugo.io/t/warning-when-mixing-html-and-markdown/52280).

---

<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 18, 2026, 1:55pm UTC](https://discourse.gohugo.io/t/adding-comments-in-a-blog-post-in-a-way-that-it-is-not-added-to-the-generated-html/52677/5 "2026-05-18T13:55:00Z")

</div>

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