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="header-navigation-wrapper"> <nav class="primary-menu-wrapper" aria-label="Horizontal" role="navigation"> <ul class="primary-menu reset-list-style"> <li class="page_item page-item-1349"><a href="#">Placeholder</a></li> <li class="page_item page-item-1346"><a href="#">Placeholder</a></li> <li class="page_item page-item-130 current_page_item current-menu-item"><a href="#" aria-current="page">Placeholder </a></li> <li class="page_item page-item-585 page_item_has_children menu-item-has-children"><a href="#">Placeholder</a><span class="icon"></span> <ul class='children'> <li class="page_item page-item-315"><a href="#">Placeholder</a></li> <li class="page_item page-item-317"><a href="#">Placeholder</a></li> <li class="page_item page-item-319"><a href="#">Placeholder</a></li> <li class="page_item page-item-669"><a href="#">Placeholder</a></li> <li class="page_item page-item-671"><a href="#">Placeholder Socken</a></li> <li class="page_item page-item-673"><a href="#">Placeholder</a></li> <li class="page_item page-item-321"><a href="#">Placeholder</a></li> <li class="page_item page-item-675 page_item_has_children menu-item-has-children"><a href="#">Placeholder</a><span class="icon"></span> <ul class='children'> <li class="page_item page-item-721"><a href="#">Placeholder</a></li> <li class="page_item page-item-718"><a href="#">Placeholder</a></li> </ul> </li> <li class="page_item page-item-325"><a href="#">Placeholder</a></li> </ul> </li> <li class="page_item page-item-271"><a href="#">Placeholder</a></li> <li class="page_item page-item-1151"><a href="#">Placeholder</a></li> <li class="page_item page-item-583"><a href="#">Placeholder</a></li> <li class="page_item page-item-269"><a href=#/">Placeholder</a></li> <li class="page_item page-item-1165 page_item_has_children menu-item-has-children"><a href="#">Placeholder</a><span class="icon"></span> <ul class='children'> <li class="page_item page-item-1169"><a href="#">Placeholder</a></li> <li class="page_item page-item-1177"><a href="#">Placeholder</a></li> <li class="page_item page-item-1173"><a href="#">Placeholder</a></li> </ul> </li> <li class="page_item page-item-1136"><a href="#">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, 1 month ago by
jonalange.
-
This topic was modified 4 years, 1 month ago by
-
Two steps
Exclude Pages from Search Results (WP internal)
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”Hi @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.
You always have search unless you disabled it functionally.
https://yourdoman/search
https://yourdomain/?s=socken
There is also API
https://yourdomain/wp-json/It’s a header nav.
Menu Locations
Desktop Horizontal
Desktop Extended
MobileIf you’re still stumped, and don’t need the navigation. Remove it from the themes header.php
@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.
The topic ‘Hide pages from menu (source code)’ is closed to new replies.
