Created
December 7, 2024 08:31
-
-
Save emre-edu-tech/ce6f178400ae7a556a94446943ecdb68 to your computer and use it in GitHub Desktop.
Filter to limit or trim product title using characters or words except on Single Product Template
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
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 | |
return wp_trim_words($title, 4); // last number = words | |
} else { | |
return $title; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment