Skip to content

Instantly share code, notes, and snippets.

@cuocsongso
Created October 18, 2019 07:24
Show Gist options
  • Save cuocsongso/674cf059804025aea6230dc92ad65fca to your computer and use it in GitHub Desktop.
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
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