A Bug in ‘AdSense for Search’ Causes Not Showing Search Results in HTTPS [Fix]

If you have recently moved your site to HTTPS, then it obvious that AdSense for 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 AdSense 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 https://www.gulshankumar.net/search-results/ with below HTML code.

    <!-- A message for noscript user -->
    <noscript>Sorry! Search results can't be displayed. Since <strong>your Web Browser do not support JavaScript or it 
    may be disabled at this moment</strong>.</noscript>
    <div id="cse-search-results"></div>
     var googleSearchIframeName = "cse-search-results";
     var googleSearchFormName = "cse-search-box";
     var googleSearchFrameWidth = 800;
     var googleSearchDomain = "www.google.co.in";
     var googleSearchPath = "/cse";
    <script src="https://www.gulshankumar.net/wp-content/uploads/2016/06/google-custom-search-results.js"></script>

    AdSense Search Results Code

  4. Replace Google hosted ‘show_afs_search.js‘ with your own hosted script.
    <script src="https://www.gulshankumar.net/wp-content/uploads/2016/06/google-custom-search-results.js"></script>
  5. Here’s final result, it is working for me.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

Subscribe our blog via Email
Get instant updates of our new blog post directly at your Mailbox.


  1. Dilshad Ahmad December 6, 2016 Reply
  2. Nagaraj December 20, 2016 Reply
  3. Jume deen khan April 22, 2017 Reply

Add a Comment

Your email address will not be published. Required fields are marked *

Please don't use SMS lang. By commenting on this article, you agree to our .