Short Description Under Product Titles in the Shop
Shows a trimmed version of each product's short description below its title on shop and category pages.
Opens WPIDE on
Code
add_action( 'woocommerce_after_shop_loop_item_title', function () {
global $product;
$words = 15; // Maximum number of words.
if ( ! $product instanceof WC_Product ) {
return;
}
$text = $product->get_short_description();
if ( '' === trim( $text ) ) {
return;
}
echo '<p class="wpide-loop-excerpt" style="font-size:.9em;margin:.4em 0;">' . esc_html( wp_trim_words( wp_strip_all_tags( $text ), $words ) ) . '</p>';
}, 4 );
Notes
Change $words to set how many words are shown.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.