Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // shorten WooCommerce product titles to 5 words
- // code goes in functions.php for your child theme
- // not tested by me
- add_filter( 'woocommerce_product_title', 'shorten_woocommerce_product_title', 10, 2 );
- function shorten_woocommerce_product_title( $title, $id ) {
- $max_words = 5;
- if ( (is_front_page() || is_shop() || is_product_tag() || is_product_category() )
- && get_post_type( $id ) === 'product' ) {
- $title_words = explode(" ", $title);
- if ( count($title_words) > $max_words ) {
- return implode( " ", array_slice( $title_words, 0, $max_words ) ) . '...';
- } else {
- return $title;
- }
- } else {
- return $title;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement