Skip to content Skip to footer

So verkürzen Sie den WooCommerce-Produkttitel für die Mobilansincht

+ Option 1: (CSS): Beschränken Sie alle WooCommerce-Produkttitel auf nur eine Zeile

 

.product-block .name {
font-size: 14px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}

+ Option 2: (PHP): Beschränken Sie alle WooCommerce-Produkttitel auf die maximale Anzahl von Wörtern

 

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;
}
}

+ Option 3: (PHP): Beschränken Sie alle WooCommerce-Produkttitel auf die maximale Anzahl von Zeichen

 

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 substr( $title, 0, 30); // change last number to the number of characters you want
} else {
return $title;
}
}