Search code examples
javascripthtmlseosearch-engine

HTML: How to get sub-links and search box display upon google search


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?


Solution

  • 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.