Shorten Product title in Woocommerce widget
-
Hello all,
I’m trying to make the product titles in my website dukayn.com 5 words long everywhere (except on the product page)
I have got the following custom code working perfectly fine on the home page & shop page. However, I’m struggling to make it work on the Woocommerce widgets. I’m referring to the widgets just above the footer: New in, Featured, On Sale, Our Picks
the piece of code
is_active_widget('', '','woocommerce_products-2')
doesn’t seem to have any effect// Shorten product title page // Automatically shortens WooCommerce product titles on the main shop, category, and tag pages // to a specific number of words function short_woocommerce_product_titles_words( $title, $id ) { if ( (is_front_page() || is_shop() || is_product_tag() || is_active_widget('', '', 'woocommerce_products-2') || is_active_widget('', '', 'woocommerce_products-3') || is_active_widget('', '', 'woocommerce_products-4') || is_active_widget('', '', 'woocommerce_products-5') || is_product_category() ) && get_post_type( $id ) === 'product' ) { $title_words = explode(" ", $title); if ( count($title_words) > 5 ) { return implode(" ", array_slice($title_words, 0, 5)) . '...'; } else { return $title; // If the title isn't longer than 5 words, it will be returned in its full length without the ellipsis } } else { return $title; } } add_filter( 'the_title', 'short_woocommerce_product_titles_words', 10, 2 );
Anyone who have tried to do something similar and could help?
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Shorten Product title in Woocommerce widget’ is closed to new replies.