Created
October 18, 2019 07:25
-
-
Save cuocsongso/4243d97d90dd0a052c538cae446f9e11 to your computer and use it in GitHub Desktop.
Option 3: (PHP): Limit all WooCommerce product titles to max number of characters
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
| 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 | |
| } else { | |
| return $title; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment