Сократить названия продуктов на страницах архива Woocommerce

Я нашел этот код, чтобы ограничить название продукта WooCommerce и его работу. Но проблема в том, что это применимо везде, даже на одной странице продукта. Как сделать исключение, чтобы не применять на странице продукта?

add_filter( 'the_title', 'shorten_woo_product_title', 10, 2 );
function shorten_woo_product_title( $title, $id ) {
if (get_post_type( $id ) === 'product' ) {
return wp_trim_words( $title, 4, '...' ); // change last number to the number of words you want
} else {
return $title;
}
}

0

Решение

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 wp_trim_words( $title, 4, '...' ); // change last number to the number of words you want
} else {
return $title;
}
}
0

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector