# How to Insert Product Categories in Your WooCommerce Shortcodes: A Beginner’s Guide
Adding product categories to your WooCommerce website using shortcodes is a fantastic way to showcase specific product groups and improve user experience. This guide will walk you through the process, even if you’re new to WordPress and WooCommerce.
Why Use Shortcodes for Product Categories?
Shortcodes offer a simple, code-free (mostly!) method to display products. Instead of complex coding, you use a short, easily remembered tag. Imagine you want to feature “Summer Dresses” on your homepage. A shortcode can display just those products, without cluttering your page with everything else. This leads to:
- Improved website organization: Clearly separate product categories for better navigation.
- Enhanced user experience: Customers find what they need faster.
- Increased sales: Focused product displays can boost conversions.
- `per_page`: Number of products to display per page (e.g., `per_page=”12″`).
- `columns`: Number of columns to display products in (e.g., `columns=”3″`).
- `orderby`: How to sort products (e.g., `orderby=”date”`). Common options include `date`, `title`, `price`, `popularity`, `rand` (random).
- `order`: Ascending (`asc`) or descending (`desc`) order (e.g., `order=”desc”`).
- Shortcode not working? Double-check the category ID or slug. Make sure there are products assigned to that category.
- Wrong products displayed? Ensure the category ID or slug is correct and that your products are correctly categorized.
- Unexpected errors? Deactivate other plugins temporarily to see if they’re conflicting with WooCommerce.
The Basic `[products]` Shortcode and its Limitations
The most fundamental WooCommerce shortcode is `[products]`. However, it displays *all* your products. To show only specific categories, we need to extend this shortcode with attributes.
Let’s say you have a category called “Summer Dresses” with the ID “123” (you’ll find the ID in your WordPress admin panel). Using only the basic shortcode would look like this:
[products]
This will display ALL your products, not just “Summer Dresses”. This is where category attributes come in handy.
Adding Category Attributes to the `[products]` Shortcode
To display only “Summer Dresses,” you need to add the `category` attribute to your shortcode. Here’s how:
[products category=”123″]
Replace `”123″` with the actual ID of your Summer Dresses category. You can find this ID by:
1. Go to Products → Categories in your WordPress dashboard.
2. Hover over your “Summer Dresses” category. The URL will likely show something like `…?category=123`. 123 is your category ID.
This shortcode will now only display products assigned to the “Summer Dresses” category.
Using Category Names (Slug) Instead of IDs
While using IDs is reliable, using category slugs (the URL-friendly version of the name) offers a more human-readable approach. Let’s say your “Summer Dresses” category’s slug is “summer-dresses”. You’d use:
[products category=”summer-dresses”]
Note: Slugs are case-sensitive! Use the exact spelling as it appears in your WordPress admin panel.
Adding Multiple Categories
You can show products from multiple categories. Separate category IDs or slugs with commas:
[products category=”123,456,789″] // Using IDs
[products category=”summer-dresses,winter-coats,spring-jackets”] // Using slugs
Advanced Shortcode Options
The `[products]` shortcode offers many more options to customize your display. Here are a few useful ones:
Here’s an example combining multiple attributes:
[products category=”summer-dresses” per_page=”8″ columns=”4″ orderby=”price” order=”asc”]
This will display 8 “Summer Dresses” in 4 columns, sorted by price in ascending order.
Troubleshooting
By mastering these techniques, you can effectively use WooCommerce shortcodes to create targeted product displays, making your website more user-friendly and ultimately boosting your sales! Remember to always test your shortcodes after making changes to ensure they function correctly.