21

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
  • 13,079
  • 14
  • 56
  • 81
mbprouser
  • 211
  • 2
  • 3

4 Answers4

21

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
  • 362
  • 3
  • 9
15

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
  • 7,101
  • 4
  • 43
  • 56
Sam
  • 180
  • 1
  • 9
5

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
  • 51,670
  • 6
  • 121
  • 147
5

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

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

Front Matter

kimbaudi
  • 13,655
  • 9
  • 62
  • 74
  • 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