If you have recently moved your site to HTTPS, then it obvious that Custom Google Search may be not showing Search Results.
The reason is– when you switched your site to HTTPS, browser do not allow any mixed content over insecure protocol. No matter, either it is from your own domain or any external. I found that, the custom search box script which comes after generating has lots of error.
If you will directly use the above generated code, then you will see the mixed content error in the console log.
- And, it’s due to mistake in Google Custom Search Result script (http://www.google.com/afsonline/show_afs_search.js) that they are using http even when we access this script from https version URL
- The problem do not end here, one more thing- If you are using its Search Box script, chances are you have added a script with URL – http://www.google.co.in/coop/cse/brand?form=cse-search-box&lang=en
The Ultimate Solution
You need to serve all script with secure protocol (HTTPS) version code. I also faced this same problem, below I’m sharing my own code.
To fix this problem, simply follow these below steps.
- Using FTP or in WordPress directly via Dashboard > Media > Add new > Upload the search.js modified script (at your own hosting).
- Now, open your created Search Result page, where you want to see the search results. For example, to show the search result I have created a static page at www.gulshankumar.net/search/
- Replace Google hosted ‘show_afs_search.js‘ with your own hosted script.
- Here’s final result, it is working for me.
Bonus tip: Also please don’t forget to change search box script in https version
— Gulshan Kumar (@TheGulshanKumar) June 27, 2016
If you liked this tutorial, please share and let help other who recently moved to https. If you need any help, please feel free to ask me in the comment section or via email admin [at] gulshankumar.net