Influenced by various SEO tutorials, many WordPress users strive to keep their URL structure as concise as possible. Common requests include removing the category prefix or stripping the “/product/” slug from WooCommerce product URLs. While we won’t debate the exact weight of its SEO benefits today, we’ll focus on how to actually achieve this in WooCommerce.
Option 1: Use a Permalink Manager Plugin
The simplest and most reliable method to remove the “/product/” prefix is using the Permalink Manager for WooCommerce plugin. This plugin allows you to fully customize WooCommerce’s URL structure and easily remove slugs like “product”, “product_category”, and “product_tag”.
Plugin Link: Permalink Manager for WooCommerce
- Pros: Simple setup and highly flexible URL customization.
- Cons: Adds an extra plugin dependency, which might slightly impact performance.
Option 2: Use Custom Code with Rewrite Rules
If you’re comfortable with code, you can also remove the “product” prefix by adding a snippet to your theme’s functions.php file. Note that custom rewrite rules can occasionally conflict with page URLs or other plugins, so proceed with caution.
Below is an example code snippet to remove the product slug:
add_filter('register_post_type_args', 'wprs_remove_product_slug', 10, 2);
function wprs_remove_product_slug($args, $post_type) {
if ($post_type === 'product') {
$args['rewrite']['slug'] = '';
}
return $args;
}
function wprs_product_rewrite_rule() {
add_rewrite_rule('^([^/]+)(/[0-9]+)?/?$', 'index.php?product=$matches[1]', 'top');
}
add_action('init', 'wprs_product_rewrite_rule');
- Pros: Implemented using WordPress’s native functions, requiring no extra plugins.
- Cons: Requires flushing permalinks and may need custom rules for troubleshooting and edge cases.
Important Precautions
- SEO and Redirects: Removing the “product” slug can impact your SEO, especially if your site has used the default URL structure for a long time. To avoid broken links, ensure you set up 301 redirects from the old URLs to the new ones.
- Conflict Testing: Stripping the prefix might cause conflicts with other pages, posts, or custom post types that share the same slug. Thorough testing is essential to ensure site navigation remains intact.
Summary
If you want a quick and easy way to clean up your URLs, the Permalink Manager for WooCommerce plugin is your best bet. If you prefer a lightweight, code-based approach, custom rewrite rules are effective but may require more troubleshooting.
Finally, while technical optimizations can make your WooCommerce URLs cleaner, our experience shows that keeping category prefixes or “product” slugs generally has no negative impact on SEO rankings. Choose the approach that best fits your specific management style and site needs.
