Home Arrow Icon Knowledge base Arrow Icon Global Arrow Icon Can I use the [product_categories] shortcode to show only top-level categories


Can I use the [product_categories] shortcode to show only top-level categories


Yes, you can use the `[product_categories]` shortcode to show only top-level categories in WooCommerce. To do this, you need to set the `parent` attribute to `0`, which indicates that you want to display categories that do not have any parent categories (i.e., top-level categories).

Example Shortcode

To display all top-level categories, you can use the following shortcode:


[product_categories parent="0"]

You can also customize the output further by adding other attributes, such as `number`, `orderby`, and `order`. For instance, if you want to display only three top-level categories ordered by name, you could use:


[product_categories number="3" parent="0" orderby="name"]

This flexibility allows you to tailor the display of product categories to better suit your website's layout and user experience[1][2][4].

Citations:
[1] https://www.storeapps.org/woocommerce-categories-shortcodes/
[2] https://woocommerce.com/document/woocommerce-shortcodes/product-category/
[3] https://diviflash.com/woocommerce-shortcodes/
[4] https://barn2.com/blog/woocommerce-shortcodes/
[5] https://wordpress.org/support/topic/shortcode-to-show-a-specific-category/