# Find out if current page is single post

**URL:** <https://discourse.gohugo.io/t/find-out-if-current-page-is-single-post/10629>\
**Category:** support\
**Created:** [February 19, 2018, 1:03pm UTC](https://discourse.gohugo.io/t/find-out-if-current-page-is-single-post/10629 "2018-02-19T13:03:39Z")\
**Posts on this page:** 8\
**Page:** 1

<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:** [February 19, 2018, 1:03pm UTC](https://discourse.gohugo.io/t/find-out-if-current-page-is-single-post/10629/1 "2018-02-19T13:03:39Z")

</div>

Is there any way to find out, if I am in a single post page at the moment of rendering the template? I know about `.IsPage` which is true if the page is a simple page. But I want to add code to a single post (in the header) and not in list pages and “normal” pages and the home page.

---

<div class="post-metadata">

**Author:** ![kaushalmodi](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/kaushalmodi/32/2567_2.png) [@kaushalmodi](https://discourse.gohugo.io/u/kaushalmodi)\
**Post date:** [February 19, 2018, 1:12pm UTC](https://discourse.gohugo.io/t/find-out-if-current-page-is-single-post/10629/2 "2018-02-19T13:12:18Z")

</div>

You would need to add the single page layout stuff to **`single.html`**.

See:

> **[Hugo's Lookup Order](https://gohugo.io/templates/lookup-order/#examples-layout-lookup-for-regular-pages)**
>
> Hugo searches for the layout to use for a given page in a well defined order, starting from the most specific.

---

<div class="post-metadata">

**Author:** ![kaushalmodi](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/kaushalmodi/32/2567_2.png) [@kaushalmodi](https://discourse.gohugo.io/u/kaushalmodi)\
**Post date:** [February 19, 2018, 1:14pm UTC](https://discourse.gohugo.io/t/find-out-if-current-page-is-single-post/10629/3 "2018-02-19T13:14:05Z")

</div>

> [@davidsneighbour](#):
>
> and not in list pages and “normal” pages and the home page.

What is the difference between single pages and “normal” pages. You might need to give some examples.

---

<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:** [February 19, 2018, 1:17pm UTC](https://discourse.gohugo.io/t/find-out-if-current-page-is-single-post/10629/4 "2018-02-19T13:17:20Z")

</div>

A normal page would be ie. the contact page… and the other point were “LIST” pages, not single 😉

the specific user case would be the og:type tag for open graph info:

- blog post would be “article”
- all other pages would be “website”

I sniffed around in other themes and they all seem to solve this via front matter. which is a hassle for me because I imported 2000 posts from wordpress and would have to add that manually.

---

<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:** [February 19, 2018, 1:19pm UTC](https://discourse.gohugo.io/t/find-out-if-current-page-is-single-post/10629/5 "2018-02-19T13:19:02Z")

</div>

I think it might be solvable with a custom block `{{ block "type" . }}{{ end }}` and then in a single post layout file the accompanying `{{ define "main" }}article{{end}}` and everywhere else `{{ define "main" }}website{{end}}`.

---

<div class="post-metadata">

**Author:** ![kaushalmodi](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/kaushalmodi/32/2567_2.png) [@kaushalmodi](https://discourse.gohugo.io/u/kaushalmodi)\
**Post date:** [February 19, 2018, 2:51pm UTC](https://discourse.gohugo.io/t/find-out-if-current-page-is-single-post/10629/6 "2018-02-19T14:51:33Z")

</div>

> [@davidsneighbour](#):
>
> A normal page would be ie. the contact page

To Hugo, a contacts page (`contents/contact.md` or `contents/contact/index.md`) would be the same as a post page (`contents/posts/some-post.md` or `contents/posts/some-post/index.md`).. both will get rendered using `single.html` (unless you customize the `type` and/or `layout` in the front-matter).

> [@davidsneighbour](#):
>
> and the other point were “LIST” pages, not single

I didn’t follow that.

> [@davidsneighbour](#):
>
> seem to solve this via front matter. which is a hassle for me because I imported 2000 posts from wordpress and would have to add that manually

The total number is less relevant.. the number of posts where you _need to refactor_ is important.

Say you have 1950 posts and 50 non-posts.. then you need to add front-matter only to the 50 non-posts. You can then use `with` in the layout to distinguish between those 2 (or more sets) of regular 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:** [February 19, 2018, 3:07pm UTC](https://discourse.gohugo.io/t/find-out-if-current-page-is-single-post/10629/7 "2018-02-19T15:07:33Z")

</div>

> [@kaushalmodi](#):
>
> Say you have 1950 posts and 50 non-posts… then you need to add front-matter only to the 50 non-posts. You can then use with in the layout to distinguish between those 2 (or more sets) of regular pages.

yeah, well… I didn’t even think that far 🙂 that’s the best solution.

---

<div class="post-metadata">

**Author:** ![regis](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/regis/32/4958_2.png) [@regis](https://discourse.gohugo.io/u/regis)\
**Post date:** [February 19, 2018, 6:18pm UTC](https://discourse.gohugo.io/t/find-out-if-current-page-is-single-post/10629/8 "2018-02-19T18:18:38Z")

</div>

Well you could divide your content into `content/post/` and `content/page/` and drop your “normal” pages in the latter.  
From now you won’t have to specify the type in Front Matter, all of your posts will be of Type “post”, all of your “normal” pages will be of Type “page”. (not to confuse with Kind 🙂 )

Then rewrite the page url with config.toml:

```auto
[permalinks]
  page = "/:slug/"

```

I am not even sure you have to modify permalinks…
