# How to customize the title in the head

**URL:** https://discourse.gohugo.io/t/how-to-customize-the-title-in-the-head/32474
**Category:** support
**Created:** [April 22, 2021, 1:49pm UTC](https://discourse.gohugo.io/t/how-to-customize-the-title-in-the-head/32474 "2021-04-22T13:49:04Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![hzb](https://avatars.discourse-cdn.com/v4/letter/h/77aa72/32.png) [@hzb](https://discourse.gohugo.io/u/hzb)
#### Post date: [April 22, 2021, 1:49pm UTC](https://discourse.gohugo.io/t/how-to-customize-the-title-in-the-head/32474/1 "2021-04-22T13:49:05Z")

</div>

I create a folder called `thedemo` in folder `content` and have some markdown files in it, when I visit

```auto
http://localhost:1313/thedemo

```

The page’s `title` in head is `Thedemos` like picture

![](https://canada1.discourse-cdn.com/flex036/uploads/gohugo/original/2X/3/3ea5140cdf040b571a8188952becd8ba8bea7bad.png)

I want to change it to another text, such as `Study`, and my solution is

```auto
<head>
<title>{{ if eq .Title "Thedemos" }} Study {{ else }} {{ .Title }} {{ end }}</title>
</head>

```

Are there other better solutions? Thank you.

---

<div class="post-metadata">

### Author: ![zwbetz](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/zwbetz/32/16088_2.png) [@zwbetz](https://discourse.gohugo.io/u/zwbetz)
#### Post date: [April 22, 2021, 2:30pm UTC](https://discourse.gohugo.io/t/how-to-customize-the-title-in-the-head/32474/2 "2021-04-22T14:30:13Z")

</div>

One way to solve this is with custom page params. For example:

## Frontmatter

```yaml
---
title: "Thedemos"
date: 2021-04-22T09:22:06-05:00
custom_title_enabled: true
custom_title_value: Study
---

```

## Template

```plaintext
<title>
{{ if eq .Params.custom_title_enabled true }}
  {{ .Params.custom_title_value }}
{{ else }}
  {{ .Title }}
{{ end }}
</title>

```

## Usage

- If `custom_title_enabled` is true, the title is `Study`
- If `custom_title_enabled` is false, the title is `Thedemos `

---

<div class="post-metadata">

### Author: ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)
#### Post date: [April 22, 2021, 3:06pm UTC](https://discourse.gohugo.io/t/how-to-customize-the-title-in-the-head/32474/3 "2021-04-22T15:06:21Z")

</div>

> [@zwbetz](#):
>
> ```auto
> <title>
> {{ if eq .Params.custom_title_enabled true }}
> {{ .Params.custom_title_value }}
> {{ else }}
> {{ .Title }}
> {{ end }}
> </title>
> 
> ```

You can also use the fact that params with values is “truthy” so you can do:

```auto
<title>
{{ with .Params.custom_title }}
  {{ . }}
{{ else }}
  {{ .Title }}
{{ end }}
</title>

```

It’s also not uncommon to use blocks for this:

> **[Base templates and blocks](https://gohugo.io/templates/base/#define-the-base-template)**
>
> The base and block constructs allow you to define the outer shell of your master templates (i.e., the chrome of the page).

---

<div class="post-metadata">

### Author: ![hzb](https://avatars.discourse-cdn.com/v4/letter/h/77aa72/32.png) [@hzb](https://discourse.gohugo.io/u/hzb)
#### Post date: [April 23, 2021, 1:09am UTC](https://discourse.gohugo.io/t/how-to-customize-the-title-in-the-head/32474/4 "2021-04-23T01:09:28Z")

</div>

@zwbetz @bep

There may be a bit of misunderstanding between us, `thedemo` is not a page name, it is a folder name, it is located under the content folder.

Any folder under the content folder, if there is a markdown file in it. When you visit its path, such as `http://localhost:1313/thedemo`, its title will be automatically added in plural form, like it is a group.

I mean how to customize the group title. My solution can meet the requirements, but I think there should be a better solution.

Thank you.

---

<div class="post-metadata">

### Author: ![zwbetz](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/zwbetz/32/16088_2.png) [@zwbetz](https://discourse.gohugo.io/u/zwbetz)
#### Post date: [April 23, 2021, 1:14am UTC](https://discourse.gohugo.io/t/how-to-customize-the-title-in-the-head/32474/5 "2021-04-23T01:14:56Z")

</div>

You can still give a content file to a parent folder. For example, run:

hugo new thedemo/\_index.md

Then edit this file as you wish.

---

<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: [April 23, 2021, 1:27am UTC](https://discourse.gohugo.io/t/how-to-customize-the-title-in-the-head/32474/6 "2021-04-23T01:27:12Z")

</div>

If your content looks like this:

```auto
content/
└── post
    ├── post-1.md
    ├── post-2.md
    └── post-3.md

```

Hugo will use the directory name (`post`) as the title when you visit `http://localhost:1313/post/`, but by default it will be capitalized and pluralized to `Posts`.

If you wish to disable the plurarization, place this in your site configuration file (`config.toml`):

```auto
pluralizeListTitles = false

```

If you wish to use a different title, create a section page:

```auto
hugo new post/_index.md

```

And then edit the front matter:

```auto
---
title: "Something Different"
date: 2021-04-22T18:26:09-07:00
draft: true
---

```

---

<div class="post-metadata">

### Author: ![hzb](https://avatars.discourse-cdn.com/v4/letter/h/77aa72/32.png) [@hzb](https://discourse.gohugo.io/u/hzb)
#### Post date: [April 23, 2021, 1:35am UTC](https://discourse.gohugo.io/t/how-to-customize-the-title-in-the-head/32474/7 "2021-04-23T01:35:58Z")

</div>

Because in `config.toml` I set

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

```

All post and folder are `http://localhost:1313/fdsaf`, how can I know which one is the folder and which one is the post? Thank you.

---

<div class="post-metadata">

### Author: ![zwbetz](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/zwbetz/32/16088_2.png) [@zwbetz](https://discourse.gohugo.io/u/zwbetz)
#### Post date: [April 23, 2021, 1:58am UTC](https://discourse.gohugo.io/t/how-to-customize-the-title-in-the-head/32474/8 "2021-04-23T01:58:48Z")

</div>

We would have to see your specific content tree to say for sure.

---

<div class="post-metadata">

### Author: ![hzb](https://avatars.discourse-cdn.com/v4/letter/h/77aa72/32.png) [@hzb](https://discourse.gohugo.io/u/hzb)
#### Post date: [April 23, 2021, 2:46am UTC](https://discourse.gohugo.io/t/how-to-customize-the-title-in-the-head/32474/9 "2021-04-23T02:46:29Z")

</div>

@zwbetz Sorry for my mistake.

```auto
content/
├── thedemo
 | ├── study-1.md
 | └── study-2.md
├── golang
 | ├── gos-1.md
 | └── gos-2.md
└── post
    ├── post-1.md
    ├── post-2.md
    └── post-3.md

```

Code of `head.html` in my theme

```auto
<head>
<title>{{ if eq .Title "Thedemos" }} Study {{ else if eq .Title "Posts" }} SomePosts {{ else if eq .Title "
Golangs" }} Golang {{ else }} {{ .Title }} {{ end }}</title>
</head>

```

Code of `list.html`

```auto
{{ define "main" }}

{{ if eq .Title "Thedemos" }}

 //the demo list displayed style

{{ else if eq .Title "Posts" }}

//the post list displayed style

{{ else if eq .Title "Golangs" }}

//the golang list displayed style

{{ else }}

//the default list displayed style

{{ end }}

{{ end }}

```

I think there are too many judgment statements like `if else`, I think my solution is not good, I am looking for a better solution, thank you.

---

<div class="post-metadata">

### Author: ![zwbetz](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/zwbetz/32/16088_2.png) [@zwbetz](https://discourse.gohugo.io/u/zwbetz)
#### Post date: [April 23, 2021, 2:55am UTC](https://discourse.gohugo.io/t/how-to-customize-the-title-in-the-head/32474/10 "2021-04-23T02:55:29Z")

</div>

I see. So, I prefer to have my logic in template files, and my data in content files. If you would like the same, see below.

Your template logic could be reduced down to merely:

```auto
<title>{{ .Title }}</title>

```

Then in each of your folders, or [branch bundles](https://gohugo.io/content-management/page-bundles/) as Hugo calls them, you could have a `_index.md` file with the desired title.

For example, in `content/thedemo/_index.md` you would have this frontmatter:

```auto
---
title: Study
---

```

---

<div class="post-metadata">

### Author: ![hzb](https://avatars.discourse-cdn.com/v4/letter/h/77aa72/32.png) [@hzb](https://discourse.gohugo.io/u/hzb)
#### Post date: [April 23, 2021, 3:24am UTC](https://discourse.gohugo.io/t/how-to-customize-the-title-in-the-head/32474/11 "2021-04-23T03:24:30Z")

</div>

That’s cool, better than mine. Thank you.  
But, is there any better solution in the template `list.html`?

---

<div class="post-metadata">

### Author: ![zwbetz](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/zwbetz/32/16088_2.png) [@zwbetz](https://discourse.gohugo.io/u/zwbetz)
#### Post date: [April 23, 2021, 3:28am UTC](https://discourse.gohugo.io/t/how-to-customize-the-title-in-the-head/32474/12 "2021-04-23T03:28:45Z")

</div>

> [@hzb](#):
>
> But, is there any better solution in the template `list.html` ?

If you want to specify the title in a content file, then yes. See above.

---

<div class="post-metadata">

### Author: ![hzb](https://avatars.discourse-cdn.com/v4/letter/h/77aa72/32.png) [@hzb](https://discourse.gohugo.io/u/hzb)
#### Post date: [April 23, 2021, 3:34am UTC](https://discourse.gohugo.io/t/how-to-customize-the-title-in-the-head/32474/13 "2021-04-23T03:34:48Z")

</div>

> [@zwbetz](#):
>
> If you want to specify the title in a content file, then yes. See above.

@zwbetz

Not the title, your solution for the title is great.

Here I mean the content of `list.html`

```auto
{{ define "main" }}

{{ if eq .Title "Thedemos" }}

 //the demo list displayed style

{{ else if eq .Title "Posts" }}

//the post list displayed style

{{ else if eq .Title "Golangs" }}

//the golang list displayed style

{{ else }}

//the default list displayed style

{{ end }}

{{ end }}

```

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: [April 25, 2021, 3:35am UTC](https://discourse.gohugo.io/t/how-to-customize-the-title-in-the-head/32474/14 "2021-04-25T03:35:04Z")

</div>

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