Replace wordpress search with Google Custom Search (CSE)

For better search results or due to integration with Adsense you many want to replace wordpress search with Google Custom Search (CSE)

Below are the steps to follow using a simple wordpress plugin. [Download Plugin]

1. Register you site on Google Custom Search by filling a simple form as shown below

Google Custom Search
2. After creating your CSE you will get a search engine ID as shown below. Make a note of this ID.

Screen Shot 2016-01-25 at 12.10.01 PM
3. Create a page to display the search results page and add [PW_ADD_GSEARCH_RESULTS] shortcode on this page.

4. Add the the URL of the search results page on the setting screen of the plugin.

Replace wordpress search with google custom search
Settings screen

5. Comment/Remove the code in searchform.php in your themes folder of probably header.php and add below code instead

This will create the search box.