# Making code conditional

**URL:** <https://discourse.gohugo.io/t/making-code-conditional/37705>\
**Category:** support\
**Created:** [March 17, 2022, 1:27am UTC](https://discourse.gohugo.io/t/making-code-conditional/37705 "2022-03-17T01:27:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon44707125](https://avatars.discourse-cdn.com/v4/letter/a/e68b1a/32.png) [@anon44707125](https://discourse.gohugo.io/u/anon44707125)\
**Post date:** [March 17, 2022, 1:27am UTC](https://discourse.gohugo.io/t/making-code-conditional/37705/1 "2022-03-17T01:27:47Z")

</div>

I came [across this code](https://discourse.gohugo.io/t/static-comment-for-hugo/1944/17) and I have a use case for my site. How would I wrap it in a conditional so it only shows where it is needed? It works, except the heading “comments” shows up in all posts.

---

<div class="post-metadata">

**Author:** ![GhsvsDe](https://avatars.discourse-cdn.com/v4/letter/g/9fc29f/32.png) [@GhsvsDe](https://discourse.gohugo.io/u/GhsvsDe)\
**Post date:** [March 17, 2022, 2:00am UTC](https://discourse.gohugo.io/t/making-code-conditional/37705/2 "2022-03-17T02:00:43Z")

</div>

> [@anon44707125](#):
>
> except the heading “comments” shows up in all posts.

- Remove headline line 1.

- After line

```auto
{{ $filtered := where .Site.Pages "Params.parent" $url.Path }}

```

add

```auto
{{- if $filtered -}}
<h1>comments</h1>
{{- end -}}

```

---

<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:** [March 19, 2022, 2:00am UTC](https://discourse.gohugo.io/t/making-code-conditional/37705/3 "2022-03-19T02:00:49Z")

</div>

Closed on March 19, 2022, 2:00am UTC

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