# Add different head.html to homepage

**URL:** <https://discourse.gohugo.io/t/add-different-head-html-to-homepage/39133>\
**Category:** support\
**Created:** [June 17, 2022, 9:16am UTC](https://discourse.gohugo.io/t/add-different-head-html-to-homepage/39133 "2022-06-17T09:16:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bullet](https://avatars.discourse-cdn.com/v4/letter/b/e95f7d/32.png) [@bullet](https://discourse.gohugo.io/u/bullet)\
**Post date:** [June 17, 2022, 9:16am UTC](https://discourse.gohugo.io/t/add-different-head-html-to-homepage/39133/1 "2022-06-17T09:16:33Z")

</div>

Hi, everyone!

I have a task to add different head.html for homepage only (new file like head\_homepage.html). My current structure of folders looks like this:

- layouts

layouts/\_default/baseof.html looks something like this:

```auto
<!DOCTYPE html>
<html lang="{{ .Site.Language.Lang }}" class="no-js">
<head>
  {{ partial "head.html" . }}
</head>
<body...>

```

index.html looks like:

```auto
{{ define "section1" }}
  <div>...
{{ end }}

{{} define "section2" }}
  <div>...
{{ end }}

```

I changed head.html for my new head\_homepage.html in layouts/\_default/baseof.html for `{{ partial "head_homepage.html" . }}`, but was told it’s not a good approach, since this is kind of root folder and files that do not have baseof.html in their folders could be altered. So right now I’m trying to figure out the best approach to deal with the issue. Here the ideas I came up with:

1. Using hugo detect whether we are in homepage in layouts/\_default/baseof.html and use either home.html or head\_homepage.html. I’m not familiar with hugo but pseudocode will look something like this:

```auto
{{ if (Site.Url eq 'homepage') }}
    {{ partial "head.html" }}
{{ else }}
    {{ partial "head_homepage.html" . }}
{{ end }}

```

1. to add this section to head to layouts/index.html

```auto
<!DOCTYPE html>
<html lang="{{ .Site.Language.Lang }}" class="no-js">
<head>
  {{ partial "head.html" . }}
</head>
<body...>

```

1. create a baseof.html in folder layouts/baseof.html (as recommended here [How can I use a different baseof.html on the homepage?](https://discourse.gohugo.io/t/how-can-i-use-a-different-baseof-html-on-the-homepage/22247))

Could you, please, help me what approach is the best or in case none of them works, recommend some other ones?  
These pages didn’t help unfortunately [Base Templates and Blocks | Hugo](https://gohugo.io/templates/base/#define-the-base-template), [Homepage Template | Hugo](https://gohugo.io/templates/homepage/)

---

<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:** [June 17, 2022, 9:22am UTC](https://discourse.gohugo.io/t/add-different-head-html-to-homepage/39133/2 "2022-06-17T09:22:27Z")

</div>

> [@bullet](#):
>
> ```auto
> {{ if (Site.Url eq 'homepage') }}
> {{ partial "head.html" }}
> {{ else }}
> {{ partial "head_homepage.html" . }}
> {{ end }}
> 
> ```

Try:

```auto
{{ if .IsHome }}
    {{ partial "head_homepage.html" . }}
{{ else }}
    {{ partial "head.html" }}
{{ end }}

```

---

<div class="post-metadata">

**Author:** ![bullet](https://avatars.discourse-cdn.com/v4/letter/b/e95f7d/32.png) [@bullet](https://discourse.gohugo.io/u/bullet)\
**Post date:** [June 17, 2022, 9:28am UTC](https://discourse.gohugo.io/t/add-different-head-html-to-homepage/39133/3 "2022-06-17T09:28:45Z")

</div>

Worked perfectly, thank you very much!

---

<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:** [June 19, 2022, 9:29am UTC](https://discourse.gohugo.io/t/add-different-head-html-to-homepage/39133/4 "2022-06-19T09:29:43Z")

</div>

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