Advertisement
lorro

WooCommerce - Change product titles in all caps to title case

Dec 21st, 2022 (edited)
1,387
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.51 KB | None | 0 0
  1. <?php
  2.   // change product titles in all caps to title case
  3.   add_filter( 'the_title', 'custom_title_format' );
  4.   function custom_title_format( $title ) {
  5.     if( is_shop() || is_product_category() || is_product() ) {
  6.       $words = explode(  " ", $title );
  7.       $title = "";
  8.       foreach( $words as $word ) {
  9.         $word = ucfirst( strtolower( $word ) );
  10.         $title = $title.$word." ";
  11.       }
  12.         return trim( $title );
  13.     }
  14.       // return the normal Title if conditions aren't met
  15.       return $title;
  16.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement