17

How do I hide a page in Jekyll? I have a Contact Us page (as a Google Docs form), and there is a response page. When created, it shows up in the navigation as a child of the Contact Us page, but I don't want it to show up at all.

I currently have this set up in the front matter like this:

---
layout: page
title: Thanks
permalink: /contact/thanks/
---
Ryan Kohn
  • 12,541
  • 11
  • 53
  • 80
mbprouser
  • 171
  • 1
  • 3

4 Answers4

18

If you do not put any title in the page, it does not show up in the nav bar. Something like

---
layout: page
permalink: /contact/thanks/
---
Fabien
  • 332
  • 3
  • 9
14

Rather than 'opting out' of including certain pages, you can 'opt in' to include only the pages you do want included in your navigation. This is useful if you have a large number of pages.

Include a menu variable in the front matter of every page you do want included in the navigation:

---
layout: blog
title: Blog
menu: main
permalink: /blog/
---

And then add an if statement where your navigation is generated:

<ul>
  {% for page in site.pages %}
    {% if page.menu == 'main' %}
      <li><a href="{{ page.url | prepend: site.baseurl }}">{{ page.title }}</a></li>
    {% endif %}
  {% endfor %}
</ul>

This is likely to be in _layouts/default.html or possibly _includes/header.html.

Thanks to David Jaquel's answer on this question for the inspiration: Excluding page from Jekyll navigation bar

Danny Staple
  • 6,697
  • 3
  • 42
  • 55
Sam
  • 171
  • 1
  • 7
4

Just add a show_in_nav: false in you page front matter and in your navigation bar, do a :

<ul>
{% for p in pages %}
    {% unless show_in_nav == false %}
    <li><a href="{{ site.baseurl }}{{ p.url }}">{{ p.title }}</a></li>
    {% endunless %}
{% endfor %}
</ul>

This will prevent your page from appearing in navigation bar.

David Jacquel
  • 49,253
  • 6
  • 113
  • 137
1

According to docs, set published to false in your front matter:

---
layout: post
title: Blogging Like a Hacker
published: false
---

Front Matter

kimbaudi
  • 10,996
  • 6
  • 55
  • 66
  • This is not the correct approach. This would not work for 404 page which you wouldn't want to see in the header, but still wanted it to be published. – Xogle Dec 22 '16 at 19:20
  • I guess my solution is more appropriate for posts instead of pages. But the OP wants to hide a page and setting the predefined global variable `published: false` works. Besides, `title` is not a predefined variable in Jekyll (its custom) and your solution relies on checking to see if `title` exists in the front matter (`{% for my_page in site.pages %}` `{% if my_page.title %}`), unless that is how its handled in GitHub pages and that can't be changed. – kimbaudi Dec 22 '16 at 23:44