<p>There are two very different questions here, but I will try my best to answer them both!</p>

<p>The first being "<strong>How do I hide a page from the navigation?</strong>"</p>

<p>The simplest way I can think of for this, that is also controllable through Craft, is to create a simple "Hide from navigation" <a href="http://buildwithcraft.com/docs/lightswitch-fields" rel="nofollow">Lightswitch</a> field, and add this to your entry types.</p>

<p>When looping through entries for the navigation, you can check whether the lightswitch has been checked, and if it has, don't show that entry in the nav:</p>

<pre><code>{% for entry in craft.entries.section('lorem').hideFromNavigation(0) %}
    --
{% endfor %}
</code></pre>

<p>The second question is "<strong>How do I redirect to the homepage if someone visits /services?</strong>"</p>

<p>This can be achieved with the <code>redirect</code> <a href="http://buildwithcraft.com/docs/templating/redirect" rel="nofollow">tag</a>. In your <code>services/index.twig</code> template file, you can simply add:</p>

<pre><code>{% redirect siteUrl %}
</code></pre>

CC BY-SA 3.0
2016-12-20T19:05:25.170Z
Thx for the *hideFromNavigation* tip. Exactly what I was looking for! :-)
Mario
CC BY-SA 3.0
2016-12-20T19:24:38.990Z
Had to use this syntax to exclude entries with active lightswitch: *.hideFromNavigation('not 1')*
Mario
CC BY-SA 3.0
2014-12-09T16:19:14.780Z
Not trying to hide from navigation, just want to remove link from the "Services" page and/or remove page entirely and modify code above accordingly. Any ideas?
frshjb373
CC BY-SA 3.0
2014-12-08T22:44:38.783Z
2014-12-08T22:44:38.783Z
Jamie Wade
<p>You need to add a conditional to either only run for the parent items OR exclude the children items. Using depth level would do it:</p>

<p>So instead of:</p>

<pre><code>&lt;a href="{{ page.navigationUrlOverride ? page.navigationUrlOverride : page.url }}"&gt;
</code></pre>

<p>try:</p>

<pre><code>{% if page.navigationUrlOverride and page.level == '1' %}
    &lt;a href="{{ page.navigationUrlOverride }}" /&gt;
{% else %}
    &lt;a href="{{page.url}}" /&gt;
{% endif %}
</code></pre>

CC BY-SA 3.0
2014-12-09T22:56:39.393Z
This doesn't allow you to override level 2 entries.
carlcs
CC BY-SA 3.0
2014-12-10T00:25:35.943Z
Precisely. I kept it simple to illustrate how to work around the children adopting the value of the parent while still maintaining the use of the children tag.
Jarrett Barnett
CC BY-SA 3.0
2014-12-09T22:06:48.653Z
2014-12-09T22:06:48.653Z
Jarrett Barnett
<p>As I wrote in the comments section, you could work around this strange behavior of the nav tag by replacing it with nested for loops. Use <a href="http://buildwithcraft.com/docs/templating/entrymodel#getDescendants" rel="nofollow"><code>getDescendants(1)</code></a> to get the child entries of each top-level entry.</p>

<pre><code>{% for page in pageItems %}
    &lt;li&gt;
        &lt;a href="{{ page.navigationUrlOverride ? page.navigationUrlOverride : page.url }}"&gt;
            {{ page.navigationTitle ? page.navigationTitle|nl2br : page.title }}
        &lt;/a&gt;

        {% set subPageItems = page.getDescendants(1) %}
        {% if subPageItems %}
            &lt;div class="drop"&gt;
                &lt;ul&gt;
                    {% for subPage in subPageItems %}
                        &lt;a href="{{ page.navigationUrlOverride ? page.navigationUrlOverride : page.url }}"&gt;
                            {{ page.navigationTitle ? page.navigationTitle|nl2br : page.title }}
                        &lt;/a&gt;
                    {% endfor %}
                &lt;/ul&gt;
            &lt;/div&gt;
        {% endif %}
    &lt;/li&gt;
{% endfor %}
</code></pre>

CC BY-SA 3.0
2014-12-09T23:11:59.920Z
2014-12-09T23:11:59.920Z
carlcs
<p>You can also do a simple if/else to hide the href link using a lightswitch toggle. Using Jamie's hideFromNavigation lightswitch from above, you could do the following:</p>

<pre><code>{% set entries = craft.entries.section('pages') %}
&lt;ul id="nav"&gt;
    {% nav entry in entries %}
        &lt;li&gt;
            &lt;a  {% if entry.hideFromNavigation %} href="#" {% else %} href="{{ entry.url }}" {% endif %}&gt;{{ entry.title }}&lt;/a&gt;
            {% ifchildren %}
                &lt;ul&gt;
                    {% children %}
                &lt;/ul&gt;
            {% endifchildren %}
        &lt;/li&gt;
    {% endnav %}
&lt;/ul&gt;
</code></pre>

CC BY-SA 3.0
2017-06-28T18:52:55.953Z
2017-06-28T18:52:55.953Z
EParks
<p>Trying to output navigation:</p>

<ul>
<li>Home </li>
<li>About </li>
<li>Services
<ul>
<li>Sub 1</li>
<li>Sub 2</li>
<li>Sub 3 </li>
</ul></li>
<li>List item</li>
<li>Testimonials </li>
<li>Contact </li>
<li>Get Quote</li>
</ul>

<p>I'd like to remove the link to the Services page, preferably to <code>&lt;a href"#"&gt;</code> and if accessed through url, redirect to homepage.</p>

<p>Here's how I'm currently outputting nav:</p>

<pre><code>        {# get menu items #}
        {% set pageItems = craft.entries.section('services').level('&lt;= 2') %}
        {# % set pageItems = craft.entries.level('&lt;= 2') %# }

        {# Output the sub menu #}
        &lt;ul&gt;
            &lt;li&gt;&lt;a href="{{ siteUrl }}"&gt;Home&lt;/a&gt;&lt;/li&gt;
            {% set entry = craft.entries.slug('about').first %}
            &lt;li&gt;&lt;a href="{{ entry.url }}"&gt;{{ entry.title }}&lt;/a&gt;&lt;/li&gt;

            {% nav page in pageItems %}
            &lt;li&gt;
                &lt;a href="{{ page.navigationUrlOverride ? page.navigationUrlOverride : page.url }}"&gt;
                    {% if page.navigationTitle %}{{ page.navigationTitle|nl2br }}{% else %}{{ page.title }}{% endif %}
                &lt;/a&gt;
                {% ifchildren %}
                &lt;div class="drop"&gt;
                    &lt;ul&gt;
                        {% children %}
                    &lt;/ul&gt;
                &lt;/div&gt;
                {% endifchildren %}
            &lt;/li&gt;
            {% endnav %}
        &lt;/ul&gt;
        &lt;ul&gt;
            {% set entry = craft.entries.slug('testimonials').first %}
                &lt;li&gt;&lt;a href="{{ entry.url }}"&gt;{{ entry.title }}&lt;/a&gt;&lt;/li&gt;
            {% set entry = craft.entries.slug('contact').first %}
                &lt;li&gt;&lt;a href="{{ entry.url }}"&gt;{{ entry.title }}&lt;/a&gt;&lt;/li&gt;
            {% set entry = craft.entries.slug('get-a-quote').first %}
                &lt;li&gt;&lt;a href="{{ entry.url }}"&gt;{{ entry.title }}&lt;/a&gt;&lt;/li&gt;
        &lt;/ul&gt;
</code></pre>

<p>Any help is much appreciated. Thanks in advance.</p>

CC BY-SA 3.0
2014-12-09T09:21:26.483Z
Your code does actually look good to me? You use a plain text field `navigationUrlOverride` to overwrite the URL with `#` from the CP, right?
carlcs
CC BY-SA 3.0
2014-12-09T20:55:35.977Z
I tried that, but it adds `#` to all children. Want the children links to work.
frshjb373
CC BY-SA 3.0
2014-12-09T21:07:14.763Z
Sounds like a bug to me. You could work around this by replacing the `nav` tag with nested `for` loops.
carlcs
<navigation><templating>
Remove page link from navigation
# Remove page link from navigation

(Asked by: username_0 on 2014-12-08)

Trying to output navigation:

Home 
About 
Services

Sub 1
Sub 2
Sub 3 

List item
Testimonials 
Contact 
Get Quote

I'd like to remove the link to the Services page, preferably to  and if accessed through url, redirect to homepage.
Here's how I'm currently outputting nav:
        {# get menu items #}
        {% set pageItems = craft.entries.section('services').level('<= 2') %}
        {# % set pageItems = craft.entries.level('<= 2') %# }

        {# Output the sub menu #}
        
            Home
            {% set entry = craft.entries.slug('about').first %}
            {{ entry.title }}

            {% nav page in pageItems %}
            
                
                    {% if page.navigationTitle %}{{ page.navigationTitle|nl2br }}{% else %}{{ page.title }}{% endif %}
                
                {% ifchildren %}
                
                    
                        {% children %}
                    
                
                {% endifchildren %}
            
            {% endnav %}
        
        
            {% set entry = craft.entries.slug('testimonials').first %}
                {{ entry.title }}
            {% set entry = craft.entries.slug('contact').first %}
                {{ entry.title }}
            {% set entry = craft.entries.slug('get-a-quote').first %}
                {{ entry.title }}
        

Any help is much appreciated. Thanks in advance.

**Tags:** navigation, templating

> **Comments:**
> **username_1**: Your code does actually look good to me? You use a plain text field `navigationUrlOverride` to overwrite the URL with `#` from the CP, right?  
> **username_0**: I tried that, but it adds `#` to all children. Want the children links to work.  
> **username_1**: Sounds like a bug to me. You could work around this by replacing the `nav` tag with nested `for` loops.  

---

## 4 answers

### Answer by username_2 on 2014-12-08. Score: 5

There are two very different questions here, but I will try my best to answer them both!
The first being "How do I hide a page from the navigation?"
The simplest way I can think of for this, that is also controllable through Craft, is to create a simple "Hide from navigation" Lightswitch field, and add this to your entry types.
When looping through entries for the navigation, you can check whether the lightswitch has been checked, and if it has, don't show that entry in the nav:
{% for entry in craft.entries.section('lorem').hideFromNavigation(0) %}
    --
{% endfor %}

The second question is "How do I redirect to the homepage if someone visits /services?"
This can be achieved with the redirect tag. In your services/index.twig template file, you can simply add:
{% redirect siteUrl %}

> **Comments:**
> **username_0**: Not trying to hide from navigation, just want to remove link from the "Services" page and/or remove page entirely and modify code above accordingly. Any ideas?  
> **username_3**: Thx for the *hideFromNavigation* tip. Exactly what I was looking for! :-)  
> **username_3**: Had to use this syntax to exclude entries with active lightswitch: *.hideFromNavigation('not 1')*  

---

### Answer by username_4 on 2014-12-09. Score: 2

You need to add a conditional to either only run for the parent items OR exclude the children items. Using depth level would do it:
So instead of:


try:
{% if page.navigationUrlOverride and page.level == '1' %}
    
{% else %}
    
{% endif %}

> **Comments:**
> **username_1**: This doesn't allow you to override level 2 entries.  
> **username_4**: Precisely. I kept it simple to illustrate how to work around the children adopting the value of the parent while still maintaining the use of the children tag.  

---

### Answer by username_1 on 2014-12-09. Score: 2

As I wrote in the comments section, you could work around this strange behavior of the nav tag by replacing it with nested for loops. Use getDescendants(1) to get the child entries of each top-level entry.
{% for page in pageItems %}
    
        
            {{ page.navigationTitle ? page.navigationTitle|nl2br : page.title }}
        

        {% set subPageItems = page.getDescendants(1) %}
        {% if subPageItems %}
            
                
                    {% for subPage in subPageItems %}
                        
                            {{ page.navigationTitle ? page.navigationTitle|nl2br : page.title }}
                        
                    {% endfor %}
                
            
        {% endif %}
    
{% endfor %}


---

### Answer by username_5 on 2017-06-28. Score: 1

You can also do a simple if/else to hide the href link using a lightswitch toggle. Using Jamie's hideFromNavigation lightswitch from above, you could do the following:
{% set entries = craft.entries.section('pages') %}

    {% nav entry in entries %}
        
            {{ entry.title }}
            {% ifchildren %}
                
                    {% children %}
                
            {% endifchildren %}
        
    {% endnav %}


---

