Skip to content

Instantly share code, notes, and snippets.

@Acephalia
Last active April 1, 2023 04:26
Show Gist options
  • Save Acephalia/7acd862d239a587d14ab7935142d9c71 to your computer and use it in GitHub Desktop.
Save Acephalia/7acd862d239a587d14ab7935142d9c71 to your computer and use it in GitHub Desktop.
Truncate Woocommerce Product Titles
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' && strlen( $title ) > 30 ) {
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