A Bug in Google Custom Search Engine Causes Not Showing Search Results in HTTPS [Fix]


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.

Mixed content in Custom Google Search script
Console Log reporting Mixed content error
    • 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

      Problem: Google serving iframe in HTTP version instead of HTTPS
  • 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.

  1. Since, this script(http://www.google.com/afsonline/show_afs_search.js) has inlined http protocol. So, you need to replace this with this HTTPS enabled JavaScript code and save on your computer with name search.js. This code is little modified by me to make it working 100%.

  2. Using FTP or in WordPress directly via Dashboard > Media > Add new > Upload the search.js modified script (at your own hosting).
  3. 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/Search Results
  4. Replace Google hosted ‘show_afs_search.js‘ with your own hosted script.


  5. Here’s final result, it is working for me. See demo

    cutom google search

Bonus tip: Also please don’t forget to change search box script in https version

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