You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Prestashop 1.7:移除产品URL中的#/1-size-4等属性后缀

How to Remove Variant Attribute Suffixes Like #/1-size-4 from Product URLs

Absolutely, you can eliminate those annoying variant-related suffixes like #/1-size-4 from your product URLs. These are almost always tied to variant selection tracking (for sizes, colors, etc.)—either added by frontend JavaScript or baked into your platform’s URL generation logic. Let’s walk through the steps to fix this, based on common e-commerce setups:

1. Audit Your Frontend JavaScript

First, check the client-side code that handles product variant selection:

  • Open your browser’s dev tools (F12), go to the Sources tab, and search for terms like hash, variant, or the specific suffix pattern (#/1-size-).
  • Look for code that runs when you select a variant (e.g., a dropdown change event) and modifies window.location.hash. It might look something like this:
    document.querySelector('#size-select').addEventListener('change', function() {
      const variantId = this.value;
      window.location.hash = `#/${variantId}-size-${this.options[this.selectedIndex].text}`;
    });
    
  • If you find this, comment out or delete the line that updates the hash. Just note: if your site uses the hash to load variant data dynamically, you’ll need to replace it with another method (like a hidden input field or localStorage) to pass variant info without modifying the URL.

2. Check Backend URL Generation Logic

Next, verify if the suffix is being added server-side:

  • For WooCommerce: Look into your theme’s functions.php or custom plugins for hooks like woocommerce_loop_product_link—these might be appending variant details to URLs. You can override this hook to strip any unwanted suffixes.
  • For PrestaShop: Inspect the Link::getProductLink method (either in the core or your custom modules, including the one you installed to remove IDs). The variant suffix might be added here, so you’ll need to modify the method to exclude that hash segment.
  • For Shopify: Check your theme’s product templates for code that appends variant hashes to product links. For example, if you see something like {{ product.url }}#/{{ variant.id }}-size-{{ variant.size }}, remove the hash part entirely.

3. Review Your URL/SEO Module Settings

Since you already have a module to remove URL IDs, double-check its settings:

  • Look for options like "Remove variant hash from product URLs" or "Disable variant tracking in URLs"—many URL optimization modules include this toggle.
  • If you’re using an SEO plugin, it might be adding these suffixes to track variant performance. Head to the plugin’s settings and disable any variant-related URL tracking features.

4. Test Thoroughly

After making changes:

  • Navigate to product pages from different entry points (homepage, category pages, search results) to confirm the suffix is gone.
  • Test variant selection to ensure your product still loads the correct size/color without relying on the URL hash.

内容的提问来源于stack exchange,提问作者Ciubakka

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 06:28:37