Google search box with additional Google support

We want to implement a Google sitelink search box with a regular Google search. In the Google documentation, I found that we need to include the code below to enable the link 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 in the "target" node in the above properties. Since we don’t have any search page of our own, we want to use a custom Google search method, so what value should I fill with this “target” node.

We have already created a Google search engine for our site. And found the code below 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 a search box for sitelinks, for example, Mashable , Imdb

enter image description here

Please indicate how to specify custom Google search in the link search code field.

thanks

+6
source share
3 answers

Only decision:

To do this, you need a search page on your own website.

For the "target" parameter, search on your site and take this URL and replace the search query that you used to search with "{search_term_string}"

If you create a search page on your website where you use custom Google search, you can use this link for target -property.

The reason for this is that Google does not provide a search function

send the user directly to your own search pages.

Sources:

+1
source

Shishdem links don't identify what they write for purpose, after some work on guessing it works

 https://example.com/index.html?q={search_term_string} 

for the search box included as part of the index.html page

if the search box is on the site map page, use

 https://examples.com/sitemap.html?q={search_term_string} 

I could only find this because the 404 page included a search box, so it returned 404, then the results appeared, so I changed the code.

This ignores anything else on this page and seems to produce the correct results, so it should fit in JSON-LD (or microdata if you prefer). JSON-LD might be better as Google recommends it but claims microdata is accepted. Link to the link in the original documentation.

+1
source

You will need the Google CSE WordPress plugin: https://wordpress.org/plugins/google-cse/

  • Install it.
  • Enable Custom Search API
  • Create API
  • Use the generated API and search engine user identifier
  • Find your built-in WordPress search on the site

You can now use the SearchAction Shema.org markup (Sitelink search box).

Only works with WordPress.

0
source

Source: https://habr.com/ru/post/983217/


All Articles