shortening product titles shortens all titles
-
Hi – I think a snippet of code in my functions file has “expanded” it’s reach after a WordPress update (not entirely sure how long this has been happening though).
My WooCommerce store has widely varying product titles, so we impose this function to shorten and add an ellipses at the end:
add_filter( 'the_title', 'shorten_my_title', 10, 2 ); // Shorten Post Titles (mostly for long-assed product names) function shorten_my_title( $title, $id ) { if ( is_shop() || is_product_tag() || is_product_category() && get_post_type( $id ) === 'product' && strlen( $title ) > 40 ) { return substr( $title, 0, 40 ) . '...'; } else { return $title; } }
This worked great for over a year, but now we are seeing that even our mega menu links are getting shortened. Basically it’s run amok and we can’t figure out what may have changed in WordPress (or our own user error!) that would now cause this function above to affect the menu.
Any idea what’s wrong or how we might narrow this function so it doesn’t affect our menu at all?
Thanks
Bill
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘shortening product titles shortens all titles’ is closed to new replies.