How to Remove “Product” from WooCommerce URLs: A Beginner’s Guide
Are you looking to clean up your WooCommerce store’s URLs? The default WooCommerce setup includes “product” in the URL structure, for example: `yourdomain.com/product/awesome-t-shirt/`. While functional, it’s not the prettiest or most SEO-friendly. Removing the `/product/` segment can lead to shorter, more memorable URLs, potentially improving your site’s search engine visibility and user experience.
This guide will walk you through different methods for removing “product” from your WooCommerce URLs, even if you’re new to WordPress and WooCommerce. Let’s get started!
Why Remove “Product” Check out this post: How To Use Woocommerce With Learndash from Your URLs?
Before diving into the how-to, let’s understand why you might want to make this change:
- Improved SEO: Shorter URLs are generally considered better for SEO. While the impact might be marginal, every little bit helps. Search engines prefer concise URLs that accurately reflect the page’s content.
- Better User Experience: Shorter and more descriptive URLs are easier for users to remember, share, and type. Imagine telling someone to visit `yourdomain.com/awesome-t-shirt/` versus `yourdomain.com/product/awesome-t-shirt/`. The former is cleaner and more intuitive.
- Branding Consistency: If you prioritize a clean and modern website design, removing the “product” slug contributes to a more polished look.
- Caution: Make sure you HAVE a Shop page Learn more about How To Set Up My Account Page In Woocommerce created in WooCommerce. If you don’t, this might cause issues. WooCommerce usually creates this automatically upon installation.
- Category Conflicts: This method can sometimes cause conflicts with product categories and page permalinks. If you have a category or page with the same name as a product, it might not work correctly. For example, if you have a product called “Shirts” and a category called “Shirts,” you could run into issues. In such cases, Method 2 (using a plugin) is generally more reliable.
- Check Functionality: After implementing this method, thoroughly test your website. Browse to your products, categories, and pages to ensure everything is working as expected.
- Consider Alternatives: If you encounter issues with the period method, explore using a plugin (Method 2). It offers more control and often resolves conflicts.
- Remove Product Slug: A simple and dedicated plugin for this specific task.
- Permalink Manager Lite: A more comprehensive plugin for managing all types of permalinks.
Real-life Example:
Think of your website like a physical store. Would you want to label every product aisle with “Product Aisle”? Probably not. You’d likely use more descriptive labels like “Shirts” or “Electronics.” Removing “product” from your URLs is similar – it makes your virtual store more organized and easier to navigate.
Method 1: Using the Permalink Settings (Recommended for Simplicity)
This is the easiest and safest method for most users. It relies on a built-in WooCommerce setting.
1. Login to Your WordPress Dashboard: Access your WordPress admin area at `yourdomain.com/wp-admin`.
2. Navigate to Permalinks: Go to Settings > Permalinks.
3. Product Permalink Base: Look for the “Product permalinks base” section. You’ll likely see options like “Default,” “Shop base,” “Product category,” or “Custom base.”
4. Choose “Shop base”: Select the “Shop base” option. This will use the name of your Shop page (usually “Shop”) as the base URL for products. If you’re okay with your product URLs looking like `yourdomain.com/shop/awesome-t-shirt/`, this is a quick win.
5. Custom Base (If you want a complete removal): This involves a little trickery because WordPress doesn’t natively allow complete removal using just the settings. Select Read more about How To Edit Woocommerce_Cart the “Custom base” option and enter a single period: `.` (yes, just a period). This effectively removes the `/product/` slug. IMPORTANT: See the notes below *before* doing this.
6. Save Changes: Click the “Save Changes” button at the bottom of the page.
7. Flush Permalinks (Crucial!): After saving, go back to the Permalinks page and simply click “Save Changes” *again*. This forces WordPress to flush the permalinks cache, ensuring the new URL structure is correctly applied.
Important Notes about the `.` (period) Custom Base Method:
Method 2: Using a Plugin (More Robust)
Plugins provide a more powerful and reliable way to remove “product” from your WooCommerce URLs. They often handle category conflicts and other potential issues more gracefully. Here’s how:
1. Install and Activate a Plugin: Go to Plugins > Add New in your WordPress dashboard. Search for plugins like “Remove Product Slug” or “WooCommerce Permalink Manager.” Choose a reputable plugin Discover insights on How To Set Woocommerce Refunds Via Paypal with good reviews and active updates. Some popular options are:
2. Configure the Plugin: After activating the plugin, locate its settings (usually under WooCommerce or a dedicated menu item). Follow the plugin’s instructions to remove the “product” slug. Most plugins offer a simple checkbox or option to achieve this.
3. Flush Permalinks: After saving the plugin’s settings, flush your permalinks by going to Settings > Permalinks and clicking “Save Changes” (as in Method 1).
Example using “Remove Product Slug”:
This plugin is usually very straightforward. After activation, there’s often no further configuration needed. It automatically removes the “product” slug. Just flush your permalinks, and you’re done.
Reasoning: Plugins are often preferred because they provide a more controlled environment for making these changes. They’re designed to handle the complexities of WordPress and WooCommerce, reducing the risk of conflicts.
Method 3: Using Code (For Advanced Users)
This method involves adding code to your theme’s `functions.php` file or using a code snippet plugin. It’s recommended only for experienced users comfortable with PHP code. Incorrect code can break your site.
Disclaimer: Always back up your website before making code changes.
/**
$permalinks = get_option( ‘woocommerce_permalinks’ );
$product_permalink = $permalinks[‘product_base’];
// If shop base is in the permalink, trim it out.
if ( strpos( $post_link, ‘/’ . $product_permalink . ‘/’ ) !== false ) {
$post_link = str_replace( ‘/’ . $product_permalink . ‘/’, ‘/’, $post_link );
} else {
return $post_link;
}
return user_trailingslashit( $post_link, ‘product’ );
}
add_filter( ‘post_type_link’, ‘remove_product_slug’, 10, 2 );
/
* Add our custom product base rewrite rules.
*/
function add_product_rewrite_rules() {
global $wp_rewrite;
$permalinks = get_option( ‘woocommerce_permalinks’ );
$product_permalink = $permalinks[‘product_base’];
if ( ! empty( $product_permalink ) ) {
$product_permalink = trim( $product_permalink, ‘/’ );
add_rewrite_rule( ‘^’ . $product_permalink . ‘/(.*)/?$’, ‘index.php?product=$matches[1]’, ‘top’ );
} else {
add_rewrite_rule( ‘^product/(.*)/?$’, ‘index.php?product=$matches[1]’, ‘top’ );
}
$wp_rewrite->flush_rules();
}
add_action( ‘woocommerce_loaded’, ‘add_product_rewrite_rules’ );
Explanation:
- The first function, `remove_product_slug`, filters the `post_type_link` to remove the `/product/` Check out this post: How To Show Product In Stock In Woocommerce segment.
- The second function, `add_product_rewrite_rules`, adds rewrite rules to ensure that the new URLs are correctly routed to the product pages.
- `add_action( ‘woocommerce_loaded’, ‘add_product_rewrite_rules’ );` ensures that the rewrite rules are added after WooCommerce has loaded.
- `wp_rewrite->flush_rules();` in `add_product_rewrite_rules` MUST be called after making changes to rewrite rules.
Steps:
1. Backup Your Website: Before making any code changes, create a full backup of your website.
2. Add the Code: Copy the code above and paste it into your theme’s `functions.php` file (located in `wp-content/themes/your-theme-name/functions.php`) or use a code snippet plugin.
3. Flush Permalinks: Go to Settings > Permalinks and click “Save Changes” to flush the permalinks. This is essential for the code to take effect.
Code Snippet Plugin Example (Recommended over directly editing `functions.php`):
Plugins like “Code Snippets” allow you to add and manage code snippets without directly modifying your theme’s files. This is a safer and more organized approach. Install and activate the “Code Snippets” plugin, then add a new snippet with the code above. Make sure to activate the snippet.
Important Considerations After Removing “Product”
- 301 Redirects: If your website has been live for a while with the `/product/` slug, you’ll want to implement 301 redirects from the old URLs to the new URLs. This helps search engines understand that the content has moved and prevents broken links. Plugins like “Redirection” or “Yoast SEO Premium” make this process easy.
- Why Redirects are Crucial: Without redirects, visitors who click on old links (e.g., from search results or social media) will encounter 404 errors. Redirects ensure a seamless user experience and preserve your SEO ranking.
- Internal Linking: Update all internal links on your website that point to product pages to use the new URL structure.
- External Links: If possible, try to update any external links pointing to your product pages.
- Sitemap: Regenerate your website’s sitemap and submit it to search engines like Google.
- Monitoring: Keep an eye on your website’s analytics (e.g., Google Analytics) to monitor for any errors or traffic drops after making the changes.
Conclusion
Removing “product” from your WooCommerce URLs is a relatively simple task that can contribute to a cleaner, more user-friendly, and potentially more SEO-friendly website. Choose the method that best suits your comfort level and technical expertise. Remember to always back up your website and test thoroughly after making any changes. Good luck!