Ad

Regex In Shopify Filters

- 1 answer

I am trying to remove or replace ?page=2 from Shopify link with regex. Is regex not working here?

<link rel="canonical" target="_blank" rel="nofollow noreferrer" target="_blank" rel="nofollow noreferrer" href="{{ canonical_url | replace: '\?page=\d+','' }}" />
Ad

Answer

Shopify don't support regex and it will probably never support it because of security reasons. ( I'm quoting them on this )

In your case you can use the following approach in order to get only the URL:

{% assign canonical_url = canonical_url | split: '\?page=' %}
<link rel="canonical" target="_blank" rel="nofollow noreferrer" target="_blank" rel="nofollow noreferrer" href="{{ canonical_url[0] }}" />
Ad
source: stackoverflow.com
Ad