Disable Search in WordPress

You are here: Home » Blog » CMS » WordPress » Disable Search in WordPress

Disable Search in WordPress

Disable Search in WordPress: 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 WordPress search is gone.

Why can this be useful? Again, it can help if you are running your website on low spec server and do not have content that needs to be searched (probably you aren’t running a blog).

To disable WordPress on-site search, add this to the functions.php file:

function fb_filter_query( $query, $error = true ) {
if ( is_search() ) {
$query->is_search = false;
$query->query_vars[s] = false;
$query->query[s] = false;
// to error
if ( $error == true )
$query->is_404 = true;
}
}
add_action( 'parse_query', 'fb_filter_query' );
add_filter( 'get_search_form', create_function( '$a', "return null;" ) );


Related Posts:

What is SEO?

How do I install plugins in WordPress?

Change the Author Permalink Structure

Show Post Thumbnails in RSS Feed – WordPress

How do I start a WordPress blog? (hosting wordpress)

WordPress by the Numbers Facts

Choose your preferred blog CMS platform

Formatting Text in WordPress Posts (Tiny MCE Advanced for WordPress)

Create a PayPal Donation Shortcode – WordPress

Using the Current Year in Your Posts – WordPress

What is a Blog?

WordPress Posts vs Pages

How to Update: Automatically create media_buttons for shortcode selection

Protect Your Site from Malicious Requests

 

By |2019-02-08T19:25:53-04:00March 19th, 2018|Categories: CMS, WordPress|Tags: , , , , , , , |

About the Author:

I am a loving father, & husband. I am a computer enthusiast. I have used and enjoyed computers since I was young and I enjoy teaching young minds how to code, because it teaches them how to think. Today with YouTube, and social media garbage our youth are losing the ability to think on their own and solve problems. I believe this is a serious epidemic as kids today dont understand that technology is a tool. This tool is being abused, and its underlying effects are taking its toll on kids behaviour, and learning.