Syntax error sitelinks searchbox

New Member
1 0 3

 

Hello all,

 

Please do not just comment the code out as recommended above. This issue is caused by an error in the code of the template. The {{ routes.search_url }} is supposed to get replaced by Shopify's server before serving the website to your customer/Google. Unfortunately this is not happening. All you have to do is fix the code in your template. Edit your theme's code file "header.liquid" found in the Sections folder. Go to line 315 and replace the code block here with this:

{% if template.name == 'index' %}
  {% assign potential_action_target = shop.url | append: "/search?q={search_term_string}" %}
  <script type="application/ld+json">
    {
      "@context": "http://schema.org",
      "@type": "WebSite",
      "name": {{ shop.name | json }},
      "potentialAction": {
        "@type": "SearchAction",
        "target": {{ potential_action_target | json }},
        "query-input": "required name=search_term_string"
      },
      "url": {{ shop.url | append: page.url | json }}
    }
  </script>
{% endif %}

Specifically this bit here:

 

 

{% assign potential_action_target = shop.url | append: "/search?q={search_term_string}" %}

 

It replaces the broken {{ routes.search_url }} with /search which is your actual search URL. This fixes the issues in Search Console and can be verified by using the Google Structured Data Testing Tool

 

@BrianAtWork This error can also be fixed for your customers by Shopify by adding/fixing the {{ routes.search_url }} expression in the code or doing the replacing I suggested above in the standard template.

 

3 Likes
Shopify Partner
239 59 70

Hello @LushHairUK, thank you for the tip, and welcome to the Shopify Community!

 

I also noticed the liquid syntax error, and have been recommending this fix via private message for merchants who want to keep the searchbox functionality.

 

Unfortunately, I am unable to edit/update the original post that is being referenced by new readers. Would love to see a more comprehensive step-by-step post written up and have that be marked as the answer.

 

Thanks again, later!

Brian | Shopify Partner | Ecommerce Consultant
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Click Accept as Solution  
 - Need further assistance? Visit www.BrianAtWork.com

2 Likes
New Member
1 0 0

Hi,

 

Im facing the same issue in Google Search console

 

Can anyone help me the identify the error my website is > https://happypleasureph.com

0 Likes
New Member
2 0 0
My issue is fixed finally!!
Thank you for both of you, commenting out the error did not solve it, I've tried twice as first it was the wrong code I corrected.
Replacing the code as you advised finally fixed it.
Thanks for help really appreciate it.
0 Likes
New Member
1 0 0

Hi Brian

 

Hope you can help us, we are having the syntax error on our site

 

www.zeroenergymodular.co.uk 

 

I 'commented out' the code in the sections folder but the error is still showing in the search console? Could you check ive done it correctly?

 

Any help would be much appreciated, thank you in advance

 

Nick

0 Likes
New Member
1 0 0

hey @BrianAtWork 

 

i made changes as you suggested ,Pls check whether it is right or wrong 

 

my site link-

 

https://www.nutrixia.in

0 Likes
New Member
1 0 0

Hello LushHairUK,

 

I'm not comprehending what you're saying we should do to the code.

Do we take out:

 

{% assign potential_action_target = shop.url | append: "/search?q={search_term_string}" %}

 

Or do we delete everything else and leave the above code in?

 

(Everything else meaning): & leaving in the above code.

 

{% if template.name == 'index' %}
  {% assign potential_action_target = shop.url | append: "/search?q={search_term_string}" %}
  <script type="application/ld+json">
    {
      "@context": "http://schema.org",
      "@type": "WebSite",
      "name": {{ shop.name | json }},
      "potentialAction": {
        "@type": "SearchAction",
        "target": {{ potential_action_target | json }},
        "query-input": "required name=search_term_string"
      },
      "url": {{ shop.url | append: page.url | json }}
    }
  </script>
{% endif %}

 

0 Likes
New Member
1 0 0

Tnx guys, I solved this problem :)

0 Likes
New Member
10 0 0

Where is Brian's fix for this one? He never posted in the beginning, or deleted his post. Can we get a fix posted again for this issue please. Thanks!

0 Likes
New Member
10 0 0

I see the latest page with the replied statements. I've implemented the community's suggested fix and will wait a couple of days as suggested. Hopefully this can be implemented in the theme directly in future usecases. Thanks all!

0 Likes