Archived topic
Disable search index function
13 replies · Started by Jennifer on May 23, 2022
Hello, Ito increase cyber security on my websites I would like to remove the search indexing function on your theme, could you advise how I can complete this action.
Thank you
Jennifer
Hi Jennifer,
To clarify, are you wanting to keep your entire site out of search engines?
If so, you may noindex an entire site through SEO plugins like Yoast for instance.
Reference: https://yoast.com/help/how-to-noindex-an-entire-site/
Hope this clarifies. If you’re referring to something else, kindly let us know. :)
Yes when I use the URL and add key words after I want the search page option to not be available.
I've just checked the Yoast plugin and this isn't what I need to do, I need to remove the search function in the theme but still allow the URL to be searched by engines.
Apologies yes I found the function in YOAST and have resolved the issue.
Thank you
You’re welcome Jennifer! Glad you got it to work! :)
Okay I've checked the site today and the issue hasn't been resolved. if you type in /?s= then a key word say 'footy' after a URL an error search page appears in the website, this is what I would like to remove and stop occurring.
I see.
Can you try adding a PHP snippet like this through a plugin like Code Snippets:
function wpb_filter_query( $query, $error = true ) {
if ( is_search() ) {
$query->is_search = false;
$query->query_vars[s] = false;
$query->query[s] = false;
if ( $error == true )
$query->is_404 = true;
}
}
add_action( 'parse_query', 'wpb_filter_query' );
add_filter( 'get_search_form', create_function( '$a', "return null;" ) );
function remove_search_widget() {
unregister_widget('WP_Widget_Search');
}
add_action( 'widgets_init', 'remove_search_widget' );
Adding PHP reference: https://docs.generatepress.com/article/adding-php/#code-snippets
Kindly let us know how it goes. :)
Added the function code and it still shows the search function but doesn't show the key word, the message received with the search box is:
Oops! That page can’t be found.
It looks like nothing was found at this location. Maybe try searching?
Does this mean no search function is capable?
Yes, the code disables the Search functionality altogether.
To clarify, do you still want the Search functionality to work but show only the searched keyword and nothing else?
Kindly let us know.
Thank you for explaining.
To answer your question: No I'd like no search function to be available.
I see. Then I believe that function should do. Searching or using /?s= should redirect to the 404 page.
If you wish to alter the look of the 404 page, removing the search bar, you can create a Block Element - Content Template displayed to the 404 page.
Example: https://share.getcloudapp.com/Wnu71KOB
Hope this clarifies. Let us know if it doesn't work. :)
Thank you will give it a try, appreciate you help on this one.
You’re welcome Jeniffer!