Put the Category Name in the Product URL
If your SEO requirements call for putting the category slug in the product URL, this is possible. Doing this, will break some internal functions and the product View and Preview buttons from the admin will no longer work. First, put this code in your wp-config.php file:
This rewrites the slug so that it includes the product category (if you have multiple cagegores, it picks one). Secondly, put this code in your theme’s functions.php file. Your product URL’s will now look like this: http://mysite.com/products/category-parent/category-child/product-slug/.
Posted in: Helpful Code Snippets