Happening now | Office Hours: Customizing Your Theme With Moeed | Ask your questions now!

How to remove local language portion from URL path ?

Solved

How to remove local language portion from URL path ?

AdamAnas
Shopify Partner
35 1 7

How can i remove the local language portion from URL path,
{{ request.path  }} render all the URL including the "/ar/"page/example,
how can i remove the "/ar/" part from the URL path. 

Thanks in Advance 




{%- if shop.locale == 'ar' -%}
<div class="button" >
<a href="https://domain.com{{ request.path }}" >
Englsih
</a>
</div>

{%- else -%}

<div class="button" >
<a href="https://domain.com/ar{{ request.path  }}" >
arabic
</a>
</div>

{%- endif -%}

Accepted Solution (1)

Kani
Shopify Partner
468 125 233

This is an accepted solution.

Hi @AdamAnas 

 

You can do it like this 

{{ request.path | remove: request.locale.root_url }}

Kani_2-1681006740020.png

Kani_3-1681006762628.png

If you want to learn more, you can refer to this document.

https://shopify.dev/docs/api/liquid/objects/request

Hey!! ʕ ᵔᴥᵔ ʔ
Please click 'Like' and ' Accept as Solution' to encourage me to continue sharing my expertise. ♡
If you need any technical assistance, feel free to send me a DM. You no longer have to search for answers without getting a response. 🙂

View solution in original post

Replies 3 (3)

Kani
Shopify Partner
468 125 233

This is an accepted solution.

Hi @AdamAnas 

 

You can do it like this 

{{ request.path | remove: request.locale.root_url }}

Kani_2-1681006740020.png

Kani_3-1681006762628.png

If you want to learn more, you can refer to this document.

https://shopify.dev/docs/api/liquid/objects/request

Hey!! ʕ ᵔᴥᵔ ʔ
Please click 'Like' and ' Accept as Solution' to encourage me to continue sharing my expertise. ♡
If you need any technical assistance, feel free to send me a DM. You no longer have to search for answers without getting a response. 🙂
AdamAnas
Shopify Partner
35 1 7

When the customer is on the homepage and tries to back to English from Arabic, it's not working. The issue on when the user is on the homepage.

Updated code as follows


{%- if shop.locale == 'ar' -%}
<div class="site-nav__link site-nav__link--icon" >
<a href="{{store.url}}{{ request.path | remove: request.locale.root_url }}" >
Englsih
</a>
</div>
{%- else -%}
<div class="site-nav__link site-nav__link--icon" >
<a href="{{store.url}}/ar{{ request.path | replace: canonical_url, "" }}" >
arabic
</a>
</div>
{%- endif -%}

Kani
Shopify Partner
468 125 233

Hi @AdamAnas 

 

You can certainly concatenate the URL yourself.

<a href="//{{ shop.domain | append: request.path | remove: request.locale.root_url }}" >

Also, please pay attention to some information mentioned in the documentation.

Kani_0-1681110110533.png

 

Hey!! ʕ ᵔᴥᵔ ʔ
Please click 'Like' and ' Accept as Solution' to encourage me to continue sharing my expertise. ♡
If you need any technical assistance, feel free to send me a DM. You no longer have to search for answers without getting a response. 🙂