I can’t get rid of the ellipsis and the hyphen. Is there anyone who can help?
Using the code below I was finally able to remove the Stock Codes at the end of the Product Title. But I still couldn’t get rid of the hyphen and there are three dots at the end of the product titles.
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, -1 ); // change last number to the number of WORDS you want
} else {
return $title;
}
}
I had this;
T-shirt – 953854864
Now there is this;
T-shirt -…
2
Answers
Thank you very much. For some reason the code you wrote didn't work on my site. This is how I got rid of the characters I don't want; @LoicTheAztec
Try instead the following using
preg_replace()
to remove, for example " – 953854864" substring from "T-shirt – 953854864" product title:It should work.