2

i have a website www.mysite.com and a google custom search engine in www.mysite.com/google-search-engine/

i want to add google sitelinks search box to my website search engine resault page.

i have this examples:

Put the schema.org markup on my homepage.

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


<div itemscope itemtype="http://schema.org/WebSite">
  <meta itemprop="url" content="https://www.example.com/"/>
  <form itemprop="potentialAction" itemscope itemtype="http://schema.org/SearchAction">
    <meta itemprop="target" content="https://query.example.com/search?q={search_term_string}"/>
    <input itemprop="query-input" type="text" name="search_term_string" required/>
    <input type="submit"/>
  </form>
</div>

how to do this in magento home page?

google blog guide

a. "url"—This property specifies the URL of your website. It must match the canonical URL of your domain's homepage.

b.potentialAction:target—This property specifies a search URL pattern for sending queries to your site's search engine. Key points about the URL pattern: -It must include a string enclosed in curly braces that is a placeholder for the user's search query (e.g., {search_term_string}). The string inside the curly braces must also appear in the name attribute of the query-input property. -It must point to the same domain on which the markup is found. -An actual query string instead of the placeholder string must produce a valid search results page on your site.

c.query-input—the value for the name attribute of query-input must match the string enclosed inside curly braces in the target property of potentialAction.

this is an image for "sitelinks search box in search engine resault page": enter image description here

2
  • you can simply add these code block in your cms page (choose home page). you need to change target url. Apr 24, 2015 at 2:38
  • @AdarshKhatri i should change target url to what?
    – Moh3n
    Apr 24, 2015 at 2:44

2 Answers 2

2

you can do this functionality easily with use of static block and little local.xml change

just create first static block from cms menu in admin with id google_sitelinks_searchbox_js

and add this code to your block

<script type="application/ld+json">
        {
            "@context": "http://schema.org",
            "@type": "WebSite",
            "url": "http://www.youtdomain.com/",
            "potentialAction": {
                "@type": "SearchAction",
                "target": "http://www.youtdomain.com/catalogsearch/result/?q={search_term}&order=relevance&dir=desc",
                "query-input": "required name=search_term"
                }
        }
</script>

after that just add below xml code to your local.xml

<cms_index_index>    
     <reference name="before_body_end">
     <block type="cms/block" name="google_sitelinks_searchbox">
            <action method="setBlockId"><block_id>google_sitelinks_searchbox_js</block_id></action>
        </block>  
    </reference>    
</cms_index_index>

and you then clear cache and see this js code on home page source.

hope this will work for you.

6
  • unfortunatly this has disabled my sitemap from google search engine resault page!
    – Moh3n
    May 3, 2015 at 10:06
  • it's working for me. Don't when you wrong..
    – liyakat
    May 3, 2015 at 13:27
  • Do i need to rebuild my sitemap after doing this solution ?
    – Moh3n
    May 3, 2015 at 17:02
  • and where should i put this code in my local.xml exactly?
    – Moh3n
    May 3, 2015 at 17:04
  • under <cms_index_index> tag which is already mention in my answer.i would be happy if you vote up so atleast someone can trust and use this answer
    – liyakat
    May 3, 2015 at 17:27
1

If you want to have it in search results page, then you will need to add new block in your xml.

Go to your theme/layout/catalogsearch.xml and find <reference name="content"> add following code after that line-

<block type="core/template" name="google-search" template="page/google.phtml"/>

Now create a file called google.phtml in your template/page folder. And paste your google code in that page.

<script type="application/ld+json">
{
  "@context": "http://schema.org",
  "@type": "WebSite",
  "url": "http://localhost/magento/",
  "potentialAction": {
    "@type": "SearchAction",
    "target": "http://localhost/magento/index.php/catalogsearch/result/?q={search_term_string}",
    "query-input": "required name=search_term_string"
  }
}
</script>


<div itemscope itemtype="http://schema.org/WebSite">
  <meta itemprop="url" content="http://localhost/magento/"/>
  <form itemprop="potentialAction" itemscope itemtype="http://schema.org/SearchAction">
    <meta itemprop="target" content="http://localhost/magento/index.php/catalogsearch/result/?q={search_term_string}"/>
    <input itemprop="query-input" type="text" name="search_term_string" required/>
    <input type="submit"/>
  </form>
</div>

You will need to change http://localhost/magento/ to your domain name. After this clear your cache, and it should appear in your search result page.

I haven't tested this on live site, should work though.

UPDATE 1

Add following code in to your cms > home page > content area:

<script type="application/ld+json">
{
   "@context": "http://schema.org",
   "@type": "WebSite",
   "url": "http://www.yoursite.com/",
   "potentialAction": {
     "@type": "SearchAction",
     "target": "http://www.yoursite.com/catalogsearch/result/?q={search_term_string}",
     "query-input": "required name=search_term_string"
   }
}
</script>
2
  • i don't want it to be in magento search result page. i want it to be in home page. can you read my question again pleas? i updated it.
    – Moh3n
    Apr 24, 2015 at 3:22
  • Try this then: cse.google.com/cse/manage/all Apr 24, 2015 at 5:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.