Skip to content

Instantly share code, notes, and snippets.

@cuocsongso
Created October 18, 2019 07:25
Show Gist options
  • Select an option

  • Save cuocsongso/4243d97d90dd0a052c538cae446f9e11 to your computer and use it in GitHub Desktop.

Select an option

Save cuocsongso/4243d97d90dd0a052c538cae446f9e11 to your computer and use it in GitHub Desktop.
Option 3: (PHP): Limit all WooCommerce product titles to max number of 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 substr( $title, 0, 30); // change last number to the number of characters you want
} else {
return $title;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment