5

So if I google StackOverflow, I get the following result (with a search bar):

enter image description here

Is there a way to get this search box to display on my website using some HTML or Javascript code?

AndrewL64
  • 15,794
  • 8
  • 47
  • 79
Henry Zhu
  • 2,488
  • 9
  • 43
  • 87

2 Answers2

3

You need to add some Schema Code to your website's HTML like this:

<script type=”application/ld+json”>

{

“@context”: “http://schema.org”,

“@type”: “WebSite”,

“url”: “https://www.example.com/”,

“potentialAction”: {

“@type”: “SearchAction”,

“target”: “https://query.example.com/search?q={search_term_string}”,

“query-input”: “required name=search_term_string”

}

}

</script>

After adding the above Schema Code, you will have to submit your URL to Google via this link: https://developers.google.com/structured-data/testing-tool/


N.B. You will need to change the url and target links to your own domain.

AndrewL64
  • 15,794
  • 8
  • 47
  • 79
2

What you refer to as "sub links" are sitelinks and this is what Google says about their generation:

"We only show sitelinks for results when we think they'll be useful to the user. If the structure of your site doesn't allow our algorithms to find good sitelinks, or we don't think that the sitelinks for your site are relevant for the user's query, we won't show them.

At the moment, sitelinks are automated. We're always working to improve our sitelinks algorithms, and we may incorporate webmaster input in the future. There are best practices you can follow, however, to improve the quality of your sitelinks. For example, for your site's internal links, make sure you use anchor text and alt text that's informative, compact, and avoids repetition.

If you think that a sitelink URL is inappropriate or incorrect, you can demote it. Demoting a URL for a sitelink tells Google that you don't consider this URL a good sitelink candidate for a specific page on your site. Google doesn't guarantee that demoted URLs will never appear as a sitelink, but we do consider a demotion a strong hint that we'll try to honor when generating sitelinks."

https://support.google.com/webmasters/answer/47334?hl=en

I imagine that supporting a sitemap will make it easier for you to promote the urls you want to be visible as a sitelink.

E. Sundin
  • 4,103
  • 21
  • 30
  • yea dito I still prefer the good old classy sitemap. few of my sub pages have become sitelinks by google but not all and I keep improving my website structure and it's still a mess. from what I have learned is that they don't care if a website is popular, it's just the clear sturcture that matters. the sitemap only helps them where to begin with. – Thielicious Sep 01 '16 at 21:09