We want to implement Google sitelink search box with Google custom search. In the Google documentation, I found that we need to include the below code to enable sitelink search box
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "WebSite",
"url": "https://www.example-petstore.com/",
"potentialAction": {
"@type": "SearchAction",
"target": "https://query.example-petstore.com/search?q={search_term_string}",
"query-input": "required name=search_term_string"
}
}
</script>
But we are stuck at "target" node in the above properties. Since we dont have any own search page, we want to use Google custom searh, so what value should I fill in this "target" node.
We have already created a Google custom search engine for our site. And found below code there
<script>
(function() {
var cx = 'CX_ID';
var gcse = document.createElement('script');
gcse.type = 'text/javascript';
gcse.async = true;
gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') +
'//www.google.com/cse/cse.js?cx=' + cx;
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(gcse, s);
})();
</script>
<gcse:search></gcse:search>
We want to implement sitelink search box like Mashable, Imdb
Please suggest, how to point Google custom search in sitelink search box code.
Thanks
Important: Google doesn't guarantee that a sitelinks search box will be shown in search results. Additionally, using the sitelinks search box markup doesn't make it more likely that a sitelinks search box will be shown.
Here are the steps to make your site eligible to display with a search box in Google Search results: Sitelinks search queries send the user to the search results page for your site or app, so you need a functioning search engine to power this feature. Websites: Set up a search engine on your website.
Google Search may automatically expose a search box scoped to your website when it appears as a search result, without you having to do anything additional to make this happen. This search box is powered by Google Search.
Sitelinks search queries send the user to the search results page for your site or app, so you need a functioning search engine to power this feature. Websites: Set up a search engine on your website.
The only solution:
For this you need a search page on your own website.
For the "target" parameter, do a search on your site and take that URL and replace the search term you used to do the search with "{search_term_string}"
If you make a search page on your website where you use a custom Google Search, you should be able to take that link for the target
-property.
The reason for this is that Google does not supply the search functiop
will send the user directly to your website's own search pages.
Sources:
Shishdem's links do not identify what the write for the target either, after some guess work this works
https://example.com/index.html?q={search_term_string}
for a search box included as a part of the index.html
page
if you search box is on the sitemap page use
https://examples.com/sitemap.html?q={search_term_string}
I was only able to find this because the 404 page included the search box, so it returned 404 then results appeared, so I tweaked the code.
This ignores anything else on that page and appears to come up with the right results, so should fit into the JSON-LD (or microdata if you prefer). JSON-LD might be better since google recommends it but states microdata is accepted. Reference to link in original question documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With