Created
October 18, 2019 07:24
-
-
Save cuocsongso/674cf059804025aea6230dc92ad65fca to your computer and use it in GitHub Desktop.
+ Option 2: PHP): Limit all WooCommerce product titles to max number of words
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter( 'the_title', 'shorten_woo_product_title', 10, 2 ); | |
function shorten_woo_product_title( $title, $id ) { | |
if ( ! is_singular( array( 'product' ) ) && get_post_type( $id ) === 'product' ) { | |
return wp_trim_words( $title, 4, '...' ); // change last number to the number of words you want | |
} else { | |
return $title; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment