AI Verified

Name

Disable Search in WordPress

About

The search feature of WordPress has been around for a long time. However, if your website does not need it, or you do not want users to “search” through your website for some reason, you can use this code snippet. Essentially, it is a custom function that simply nullifies the search feature. Not just the search bar in your sidebar or the menu, but the entire concept of native WP search is gone.

Language

PHP

Rating

Voted: 1 by 3 user(s)

Link for further information:

The author has provided the following URL that may be helpful to setting up or using this snippet:

https://themeisle.com/blog/code-snippets-for-wordpress/

Codevault

Rebel

Scroll down to see more snippets from this codevault.

Wordpress Compatability

The author has indicated that this snippet is compatable up to wordpress version: Not Specified

Our AI bot has checked this snippet is compatable up to wordpress version: 6.1

Code Snippet Plugin Sync

Free & Pro

Download this snippet by clicking the download button, then head over to the Code Snippet Plugin settings in your wordpress admin dashboard, select the import menu then upload this file to import into your wordpress site.

Pro Only (Coming Soon)

You will be able to click a button and sync this snippet to your wordpress site automatically and from your dashboard manage all code snippets across all your wordpress sites that have the Code Snippets Pro plugin installed.

History

Last modified:

09/12/2023

Important Note

This snippet has the following status:

AI Verified

This snippet has been tested by our AI bot, see any comments below.

AI Bot Comments:

Found 0 vulnerabilities

Disable Search in WordPress

 
                    
1function fb_filter_query( $query, $error = true ) {
2 if ( is_search() ) {
3 $query->is_search = false;
4 $query->query_vars[s] = false;
5 $query->query[s] = false;
6 // to error
7 if ( $error == true ){
8 $query->is_404 = true;
9 }
10 }
11}
12 
13add_action( 'parse_query', 'fb_filter_query' );
14add_filter( 'get_search_form', create_function( '$a', "return null;" ) );

1

Related Snippets

Please see some snippets below related to this snippet..

Performance

Unverified

1

Convert Uploaded Images to WebP Format

Added: 6 months ago

Last Updated: 4 months ago

Convert Uploaded Images to WebP Format

Performance

AI Verified

33

Remove Unused Javascript

Added: 1 year ago

Last Updated: 1 day ago

Remove Unused Javascript - and improve your Page Speed Insight Score

Performance

AI Verified

1

Remove Google Fonts (Non Elementor)

Added: 1 year ago

Last Updated: 3 months ago

Removed Google Fonts for Non Elementor Websites

Other Snippets in this Codevault

These are some popular snippets from this users codevault..

WordPress Admin

AI Verified

1

Disable Wordpress Admin Bar

Added: 1 year ago

Last Updated: 1 year ago

The WordPress Admin Bar provides handy links to several key functions such as the ability to add new posts and pages, etc. However, if you find no use for it and wish to remove it just activate this s...

Performance

AI Verified

1

Disable Search in WordPress

Added: 1 year ago

Last Updated: 7 months ago

The search feature of WordPress has been around for a long time. However, if your website does not need it, or you do not want users to “search” through your website for some reason, you can use this...