mirror of
https://gh.wpcy.net/https://github.com/mainwp/Code-Snippets-Functions.git
synced 2026-05-01 11:52:25 +08:00
https://stackoverflow.com/questions/76512823/prevent-backend-woocommerce-product-titles-to-be-affected-by-custom-code
7 lines
351 B
Text
7 lines
351 B
Text
add_filter( 'the_title', 'shorten_woo_product_title', 10, 2 );
|
|
function shorten_woo_product_title( $title, $id ) {
|
|
if ( ! is_admin() && ! is_singular( array( 'product' ) ) && get_post_type( $id ) === 'product' ) {
|
|
$title = wp_trim_words( $title, 4, '...' ); // change last number to the number of words you want
|
|
}
|
|
return $title;
|
|
}
|