Replace WordPress search with google programmable search engine

Replace WordPress search with Google Programmable Search Engine

I decided to replace the WordPress search with Google Programmable Search Engine after realizing that the recently launched website was receiving many requests for a particular URL, which was /search.

Unwanted requests

WordPress is probably the most known system on the internet, so some people may know how to exploit any openings to harm your website.

With that in mind, I started looking for alternatives and found the best search solution I could ask for: Who is better than Google when it comes to searching?

That is what I figured, and I found the Google Programmable Search Engine, a solution to put Google search inside your website.

Why should I care about this?

Well, I’m investing some effort in having an inexpensive but robust, fast, and reliable website built with WordPress; you can read a complete article here.

That said, the search system inside WordPress opens the door to receiving data via POST requests on my server, and I want to avoid it.

Mainly for security but also to remove possible CPU and memory power usage I don’t have on a cheap server.

So, the perfect scenario is to have a way to remove the complexity of a search system from inside my website and still provide a way for users to search within my content.

How does it work?

After you create an account at Google’s Programmable Search Engine, you can insert a search box on any page you want using a script Google provides.

In my case, I created a search page:

Search page sample

It looks like you are searching inside my website, but in reality, you are searching via Google search, but my domain scopes it.

It means only results inside my domain will appear in the search results.

What about the WordPress built-in search system?

I deleted it from my website; no other exploiters can send POST requests via that route anymore.

With the help of the Disable Search plugin, I could remove the feature and free up the /search route.

Once the search route was accessible, I created a new search page and inserted the new search box.

The result

The result is a custom Google search inside my website without worrying about possible exploiters and server resources.

Search result with Google Programmable Search Engine

Was it useful for you?

If yes, consider following me on Twitter at @renatonitta.

And feel free to drop a comment or question below 👊.

Comments