33

There's any way to check if the current page is the homepage?

I want use h1 tag for the logo image only when the current page is the website base url.

Christopher
  • 3,379
  • 7
  • 25
  • 36

3 Answers3

37

You can use page.url to check if the current page is your index page:

{% if page.url == "/index.html" %}
   <h1>...</h1>
{% endif %}
Dennis Schubert
  • 640
  • 5
  • 11
  • 8
    I used `{% if page.layout == 'home' %}` but your answer is correct too. Thanks! – Christopher Mar 09 '15 at 11:48
  • 27
    I ended up using if {% if page.url == "/" %} . The rest disn't work for me. – digitaldonkey Jul 14 '16 at 18:30
  • 1
    Looks like in the version of Jekyll I just installed (3.3.1) the page.url for index.md is '/'. For example: `{% if page.url == "/" %}active{% endif %}` – pbatey Jan 09 '17 at 23:57
  • 1
    If **permalink** option is set at Front Matter of the page, *page.url* should be compared to its value. Otherwise, as said above, ```page.url == "/"``` works fine (v3.4.3). – Dmitry Demidovsky Dec 05 '17 at 14:22
11

Another option to manage this is adding page IDs to the yml frontmatter

{% if page.id == 'index' %}
  content
{% endif %}
Burak Tokak
  • 1,810
  • 1
  • 20
  • 27
Chris Peak
  • 139
  • 1
  • 3
1

Along @Christopher's comment the best is if you test the page.layout. Because if permalink is set or in other circumstances the page.url can be "/index.html", "/index", or just simply "/". Therefore I think it's more robust:

{% if page.layout == 'home' %}
  <h1>logo</h1>
{% else %}
  <h2>smaller logo</h2>
{% endif %}
Csaba Toth
  • 10,021
  • 5
  • 75
  • 121