# Show a Product Attribute in Shop Listings

> Displays the values of an attribute, such as available colors or sizes, under each product title on shop and category pages.

- Type: PHP
- Runs: Run everywhere
- Category: [WooCommerce](https://wpide.com/library/category/woocommerce/)
- Requires: WooCommerce
- Tags: woocommerce, shop, attributes
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/woo-attribute-in-loop/

## Code

```php
add_action( 'woocommerce_after_shop_loop_item_title', function () {
    $attribute = 'pa_color'; // Attribute taxonomy or local attribute name.
    $label     = 'Colors';   // Label shown before the values.

    global $product;

    if ( ! $product instanceof WC_Product ) {
        return;
    }

    $values = $product->get_attribute( $attribute );

    if ( '' === $values ) {
        return;
    }

    echo '<p class="wpide-loop-attribute" style="margin:.3em 0;font-size:.85em;color:#50575e;">' . esc_html( $label . ': ' . $values ) . '</p>';
}, 6 );
```

## Notes

Set $attribute to the attribute slug, for example pa_color for a global "Color" attribute.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Show a Product Attribute in Shop Listings" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
