Last active
April 1, 2023 04:26
-
-
Save Acephalia/7acd862d239a587d14ab7935142d9c71 to your computer and use it in GitHub Desktop.
Truncate Woocommerce Product Titles
This file contains 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' && 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