Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Limit WooCommerce Title
- // More info on https://fahimm.com
- 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;
- }
- }
- // You can try this.
- // Limit WooCommerce product titles
- function limit_woocommerce_product_title($title, $id = null) {
- $limit = 40; // Set the character limit you prefer
- if (strlen($title) > $limit) {
- $title = substr($title, 0, $limit) . '...';
- }
- return $title;
- }
- add_filter('the_title', 'limit_woocommerce_product_title', 10, 2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement