mirror of
https://gh.wpcy.net/https://github.com/mainwp/Code-Snippets-Functions.git
synced 2026-04-30 11:42:22 +08:00
https://stackoverflow.com/questions/65322993/limit-woocommerce-product-title-to-a-specific-length-and-add/65340384
8 lines
377 B
Text
8 lines
377 B
Text
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;
|
|
}
|
|
}
|