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

AI Verified

1

Enable SVG Uploads

Added: 1 year ago

Last Updated: 4 months ago

This snippet enables the ability to upload SVG files to the WordPress media library.

Performance

AI Verified

1

Remove Google Fonts (Non Elementor)

Added: 1 year ago

Last Updated: 2 months ago

Removed Google Fonts for Non Elementor Websites

Performance

AI Verified

0

Disable Lazy Loading

Added: 1 year ago

Last Updated: 6 months ago

Disable Lazy Loading

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: 6 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...