-1

Recently, we converted a theme to include variants using the link on Shopify's site. However, after we finished the tutorial, the variant number started showing up automatically in the address bar on any page with a collection. If I remove the selectCallback function from the js file, it goes away. Ideally, it would be best to not have the variant number from showing up in address bar/URL. Unfortunately, removing the selectCallback also removes some of the functionality of the variant images.

Any help on this?

Josh
  • 676
  • 1
  • 5
  • 13

2 Answers2

0

That article you linked to explains why the variant id is showing in the URL. It is required for the variant images functionality:

One component of the variant images feature is the ability to deep-link directly to a variant. This is done by appending the ?variant= query parameter to the URL of the product along with the ID of the variant.

If you want this functionality, you can't get rid of the variant id from the URL.

Also see product.selected_or_first_available_variant:

Returns the variant object of the currently-selected variant if there is a valid ?variant= query parameter in the URL.

Steph Sharp
  • 11,462
  • 5
  • 44
  • 81
  • Right. What that means is that you can link to a specific variant of an item. That doesn't mean that it has to be on each page. It shouldn't be on each page. For instance, if there are solid color shorts and plaid shorts, you can link specifically to each of them specifically without having to create separate items in the collection. Right now every URL including the base URL has a variant id at the end of it which shouldn't be happening. – Josh Jan 22 '15 at 18:47
  • @Josh Ok, perhaps try removing `enableHistoryState: true` from your js (or set it to false) instead of removing the `selectCallback` function. – Steph Sharp Jan 31 '15 at 01:58
0

When you don't want to clutter your URL with GET request parameters like that, you can always just use cookies or even better, the localStorage option of the browser. Six of one, half a dozen of the other.

David Lazar
  • 10,865
  • 3
  • 25
  • 38
  • As I mentioned above in my last comment, I'm not trying to link to anything. In fact, the links to specific variants works. However, the parameters in the URL are showing up on other pages that aren't supposed to be linking to a variant. – Josh Jan 22 '15 at 18:50
  • I was only saying, that at a higher level, you can hide that data by using cookies or local storage. Whether the data conveyed is needed or not, used correctly or not, was not my point. I have disliked GET variables in the URL since 1996... and not much has changed since to make me like them. – David Lazar Jan 22 '15 at 23:39