Title: Hide pages from menu (source code)
Last modified: March 10, 2022

---

# Hide pages from menu (source code)

 *  [jonalange](https://wordpress.org/support/users/jonalange/)
 * (@jonalange)
 * [4 years, 2 months ago](https://wordpress.org/support/topic/hide-pages-from-menu-source-code/)
 * I have no menu at all (WordPress -> Appearance -> Menus shows no menu, also in
   the Customizer is no menu).
 * One page especially should be hidden and only be accessed via directlink.
 * To not get indexed by search engines I disabled that option for this page in 
   the “Yoast Seo” plugin.
    This also excludes the page automatically from my sitemap.
   All of this is working and the page isn’t indexed by google.
 * The problem is, when I search for the page name in quotes “company name page 
   name” (for example) I can find the page, but not because google finds the page
   itself, but because on my homepage (mydomain.com) a link in the menu (that menu
   that doesn’t exist) includes a link to that page.
    So the menu and the page is
   present in html, even though I have no menu and no menu visible.
 * The html looks like this:
 *     ```
       <pre><code><div class=&quot;header-navigation-wrapper&quot;>
           <nav class=&quot;primary-menu-wrapper&quot; aria-label=&quot;Horizontal&quot; role=&quot;navigation&quot;>
               <ul class=&quot;primary-menu reset-list-style&quot;>
                   <li class=&quot;page_item page-item-1349&quot;><a href=&quot;#&quot;>Placeholder</a></li>
                   <li class=&quot;page_item page-item-1346&quot;><a href=&quot;#&quot;>Placeholder</a></li>
                   <li class=&quot;page_item page-item-130 current_page_item current-menu-item&quot;><a href=&quot;#&quot; aria-current=&quot;page&quot;>Placeholder </a></li>
                   <li class=&quot;page_item page-item-585 page_item_has_children menu-item-has-children&quot;><a href=&quot;#&quot;>Placeholder</a><span class=&quot;icon&quot;></span>
                       <ul class='children'>
                           <li class=&quot;page_item page-item-315&quot;><a href=&quot;#&quot;>Placeholder</a></li>
                           <li class=&quot;page_item page-item-317&quot;><a href=&quot;#&quot;>Placeholder</a></li>
                           <li class=&quot;page_item page-item-319&quot;><a href=&quot;#&quot;>Placeholder</a></li>
                           <li class=&quot;page_item page-item-669&quot;><a href=&quot;#&quot;>Placeholder</a></li>
                           <li class=&quot;page_item page-item-671&quot;><a href=&quot;#&quot;>Placeholder Socken</a></li>
                           <li class=&quot;page_item page-item-673&quot;><a href=&quot;#&quot;>Placeholder</a></li>
                           <li class=&quot;page_item page-item-321&quot;><a href=&quot;#&quot;>Placeholder</a></li>
                           <li class=&quot;page_item page-item-675 page_item_has_children menu-item-has-children&quot;><a href=&quot;#&quot;>Placeholder</a><span class=&quot;icon&quot;></span>
                               <ul class='children'>
                                   <li class=&quot;page_item page-item-721&quot;><a href=&quot;#&quot;>Placeholder</a></li>
                                   <li class=&quot;page_item page-item-718&quot;><a href=&quot;#&quot;>Placeholder</a></li>
                               </ul>
                           </li>
                           <li class=&quot;page_item page-item-325&quot;><a href=&quot;#&quot;>Placeholder</a></li>
                       </ul>
                   </li>
                   <li class=&quot;page_item page-item-271&quot;><a href=&quot;#&quot;>Placeholder</a></li>
                   <li class=&quot;page_item page-item-1151&quot;><a href=&quot;#&quot;>Placeholder</a></li>
                   <li class=&quot;page_item page-item-583&quot;><a href=&quot;#&quot;>Placeholder</a></li>
                   <li class=&quot;page_item page-item-269&quot;><a href=#/&quot;>Placeholder</a></li>
                   <li class=&quot;page_item page-item-1165 page_item_has_children menu-item-has-children&quot;><a href=&quot;#&quot;>Placeholder</a><span class=&quot;icon&quot;></span>
                       <ul class='children'>
                           <li class=&quot;page_item page-item-1169&quot;><a href=&quot;#&quot;>Placeholder</a></li>
                           <li class=&quot;page_item page-item-1177&quot;><a href=&quot;#&quot;>Placeholder</a></li>
                           <li class=&quot;page_item page-item-1173&quot;><a href=&quot;#&quot;>Placeholder</a></li>
                       </ul>
                   </li>
                   <li class=&quot;page_item page-item-1136&quot;><a href=&quot;#&quot;>Placeholder</a></li>
               </ul>
           </nav><!-- .primary-menu-wrapper -->
       </div><!-- .header-navigation-wrapper -->
       ```
   
 * Of course I don’t want to share the page link because then I would expose my 
   page even more.
 * Any ideas where this menu comes from even though I disabled it and have no menu?
   How do I get rid of it?
 * Thank you very much!
    -  This topic was modified 4 years, 2 months ago by [jonalange](https://wordpress.org/support/users/jonalange/).

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [backbone](https://wordpress.org/support/users/backbone/)
 * (@backbone)
 * [4 years, 2 months ago](https://wordpress.org/support/topic/hide-pages-from-menu-source-code/#post-15455407)
 * Two steps
 * Exclude Pages from Search Results (WP internal)
    [https://developer.wordpress.org/reference/hooks/pre_get_posts/](https://developer.wordpress.org/reference/hooks/pre_get_posts/)
 *     ```
       function search_filter($query) {
           if ( ! is_admin() && $query->is_main_query() ) {
               if ( $query->is_search ) {
                   $query->set( 'post__not_in', array( $post_id ) );
               }
           }
       }
       add_action( 'pre_get_posts', 'search_filter' );
       ```
   
 * If registered users is disabled, then setting the page to private would block
   it from showing in menus and Google (they still index it, just not publicly display
   it).
 * For custom page lists, add the page ID
    wp_list_pages{‘exclude=’7,17’);
 * To find the menu, which is likely a plugin or themes mobile menu, is to disable
   all plugins and reactivate one-by-one and test if hidden menu exists.
    The one
   you shared is non-descriptive besides the one instance of “Socken”
 *  Thread Starter [jonalange](https://wordpress.org/support/users/jonalange/)
 * (@jonalange)
 * [4 years, 2 months ago](https://wordpress.org/support/topic/hide-pages-from-menu-source-code/#post-15460362)
 * Hi [@backbone](https://wordpress.org/support/users/backbone/) thank you.
 * I shared this non-descriptive code so I don’t create even more results for google
   to index that would lead to a page I want to hide from public results.
 * I thought this would be enough because it’s part of the twenty twenty theme.
 * I will check the plugins, bur I highly doubt that any of my plugins causes this.
   
   The mobile menu seems plausible. How would I remove that? Because I have no menu
   set up in WP and when I look at the page on mobile I also don’t see the menu.
   It’s just in the source code and probably hidden with css (I didn’t do that).
 * Also I can’t set the page to private because it can’t be accessed at all, even
   with direct link.
 * And I don’t have a internal search I could exclude it from.
    -  This reply was modified 4 years, 2 months ago by [jonalange](https://wordpress.org/support/users/jonalange/).
    -  This reply was modified 4 years, 2 months ago by [jonalange](https://wordpress.org/support/users/jonalange/).
 *  [backbone](https://wordpress.org/support/users/backbone/)
 * (@backbone)
 * [4 years, 2 months ago](https://wordpress.org/support/topic/hide-pages-from-menu-source-code/#post-15462032)
 * You always have search unless you disabled it functionally.
    [https://yourdoman/search](https://yourdoman/search)
   [https://yourdomain/?s=socken](https://yourdomain/?s=socken) There is also API
   [https://yourdomain/wp-json/](https://yourdomain/wp-json/)
 * It’s a header nav.
    Menu Locations Desktop Horizontal Desktop Extended Mobile
 * If you’re still stumped, and don’t need the navigation. Remove it from the themes
   header.php
 *  Thread Starter [jonalange](https://wordpress.org/support/users/jonalange/)
 * (@jonalange)
 * [4 years, 2 months ago](https://wordpress.org/support/topic/hide-pages-from-menu-source-code/#post-15464911)
 * [@backbone](https://wordpress.org/support/users/backbone/) Thanks! Pretty stupid
   I didn’t looked there first. I removed the menus from the header.php now and 
   they are actually gone. I was too focused for a solution that implies some misconfiguration
   on my side and didn’t look at the theme files.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Hide pages from menu (source code)’ is closed to new replies.

 * ![](https://i0.wp.com/themes.svn.wordpress.org/twentytwenty/3.1/screenshot.png)
 * Twenty Twenty
 * [Support Threads](https://wordpress.org/support/theme/twentytwenty/)
 * [Active Topics](https://wordpress.org/support/theme/twentytwenty/active/)
 * [Unresolved Topics](https://wordpress.org/support/theme/twentytwenty/unresolved/)
 * [Reviews](https://wordpress.org/support/theme/twentytwenty/reviews/)

## Tags

 * [menu](https://wordpress.org/support/topic-tag/menu/)
 * [pre_get_posts](https://wordpress.org/support/topic-tag/pre_get_posts/)

 * 4 replies
 * 2 participants
 * Last reply from: [jonalange](https://wordpress.org/support/users/jonalange/)
 * Last activity: [4 years, 2 months ago](https://wordpress.org/support/topic/hide-pages-from-menu-source-code/#post-15464911)
 * Status: not resolved