Removing URL parameters - Recommended Products Section

Removing URL parameters - Recommended Products Section

miniSEOclub
Visitor
2 0 3

Hi there,

We would like to get rid of the parameters/string added to the product URLs when they are clicked from the "you may also like" (recommended products) section. Is there a way to alter/customize the recommended-products.liquid file code so that it loads only the product URL without the parameters that include section and product ID etc such as this:

domain/product/product-name?pr_prod_strat=collection_fallback&pr_rec_pid=5414698614950&pr_ref_pid=5428804255910&pr_seq=uniform

We want to remove those parameters as Google is starting to index this ugly/messy URLs which are obviously same as the original product URLs (content wise). Anybody has a solution to this, knows how to load/call for the original product URL without the parameters? (PS: I'm not a developer, I just need this info to guide the developers). At least to "hide" it from the end users?

(I contacted chat support for this but it wasn't helpful as they simply told me that it's because of the theme and not related to Shopify. However, I don't think this is true because I checked other random Shopify stores with different themes and I do believe that this is about Shopify's recommended products section code/the way it works. Even the code shown on Shopify dev tutorial pages indeed includes such parameters like section and product ID so I don't understand why the support don't accept that this is what their code is calling and blame it on the theme...) I mean like below code is from Shopify documentation where you can clearly see that it's calling for i.e. product ID (even I can see that as a non-tech person):

 

{% assign heading = 'You may also like' %} {% assign limit = 4 %} <div class="page-width product-recommendations" data-base-url="{{ routes.product_recommendations_url }}" data-product-id="{{ product.id }}" data-limit="{{ limit }}" data-section-id="{{ section.id }}" data-section-type="product-recommendations"> {% if recommendations.performed %} {% if recommendations.products_count > 0 %} <div class="section-header text-center"> <h2>{{ heading }}</h2> </div>

source: https://shopify.dev/tutorials/customize-theme-recommend-products

 

Thanks!

Replies 7 (7)

KaterynaD
Visitor
1 0 0

Hi, did you find out how to remove this URL parameters?

 

shree
Shopify Partner
4 0 2

Any Luck on this?

I have already found this piece of code coming from the JS on 4th step on this link - https://shopify.dev/tutorials/customize-theme-recommend-products

But removing that breaks the functionality..

tim
Shopify Partner
3981 413 1472

First of all, I doubt there is harm in having these URLS -- each product page has (should have) canonical url which points to the short form of the product url, so this should not produce any extra indexed pages.

Indeed, having these parameters in the product URL helps Shopify engine to see which of the recommended products are more relevant, helps refine its recommendations based on actual customers selections.

Anyway, the code in step 3 of the tutorial forms URL to fetch the product recommendations section and then uses it to fetch the actual HTML and "paste" it into product page. Changing it would not change the product URLs.

The actual rendering of recommended products is performed by liquid code in step 1 -- it basically calls your product-card-grid snippet, same snippet used to output product cards on collection pages:

           {% for product in recommendations.products %}
             <li class="grid__item small--one-half medium-up--one-quarter">
               {% include 'product-card-grid', max_height: 250 %}
             </li>
           {% endfor %}

 

So, if you still really want to remove those URL parameters, I'd go into product-card-grid snippet  code, find something similar to 

href="{{ product.url }}"

and replace it with

href="{{ product.url | split: "?" | first }}"

 Your theme may use different snippet name, but the idea is the same.

If my post is helpful, consider liking it -- it will help others with similar problem to find a solution.
I can be reached via e-mail tairli@yahoo.com
PavelLin
Excursionist
20 4 10

Thanks Tim! Used this solution for Dawn theme across the site.
To remove parameters in Search as well, had to amend all of the href instances (item.url and card_product.url) in the following files:
main-search.liquid, predictive-search.liquid, card-product.liquid. 

Darius90
Shopify Partner
47 1 12

I just did the same as you mentioned above. But I have concerns that parameters have a purpose and without params will start showing wrong recommended products. What do you think about it? @tim 

...
Ash88
Not applicable
2 0 0

Hi Tim,

I'm hoping you can help me with a related issue. I'd like to block selected URLs from our Shopify because the recommended product section at the bottom of each page is displaying / creating a longer URL than it should. At the end of each URL, there's an extra bit like this: "?pr_prod_strat=use_description&". This has caused problems in Google Search Console and I want to block these to stop these pages from being crawled. If you could assist me that would be greatly appreciated! 

frankymartin
Shopify Partner
32 0 22

Hi , the solution is:

 

- Go to card.product.liquid file (could be another file)
- Search for "card_product.url"
- Replace all by "card_product.url | split: "?" | first"

 

Example:
<div class="card-wrapper">
<a href="{{ card_product.url | default: '#' }}" class="full-unstyled-link">
<span class="visually-hidden">{{ card_product.title | escape }}</span>
</a>

By :

<div class="card-wrapper">
<a href="{{ card_product.url | default: '#' | split: "?" | first }}" class="full-unstyled-link">
<span class="visually-hidden">{{ card_product.title | escape }}</span>
</a>