srikat

Untitled

Oct 3rd, 2016
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. //* Limit Product Title to n Characters
  2. function shorten_woo_product_title( $title, $id ) {
  3. if ( is_admin() ) {
  4. return $title; // return the normal product title
  5. } elseif ( is_shop() || is_product_tag() || is_product_category() ) {
  6. if ( strlen( $title ) >= 32) { // if the product title is longer than n characters
  7. return substr( $title, 0, 32 ) . '...'; // Shorten it to be char limit and add ellipsis at the end
  8. } else {
  9. return $title; // return the normal product title
  10. }
  11. } else {
  12. return $title; // return the normal product title
  13. }
  14. }
  15. add_filter( 'the_title', 'shorten_woo_product_title', 10, 2 );
Advertisement
Add Comment
Please, Sign In to add comment