When you deal with WooCommerce websites, you also need to look into design, readability, and accessibility. And if you have hundreds or thousands of products, you probably need to set some global rules so that you don’t need to worry about editing each product manually.
One rule could be the way product titles are displayed. Maybe you have a mix of capitalized product names (“Red Square Table”), non-capitalized ones (“White round chair”) and all caps ones (“GREEN COUCH”), and therefore you’re looking for a PHP shortcut to fix this automatically.
So, here’s a super simple solution to capitalize all product titles. Enjoy!
PHP Snippet: Capitalize Product Titles @ Shop & Single Product Pages
/**
* @snippet Capitalize Product Title @ Shop, Single Product
* @how-to businessbloomer.com/woocommerce-customization
* @author Rodolfo Melogli, Business Bloomer
* @compatible WooCommerce 7
* @community https://businessbloomer.com/club/
*/
add_filter( 'the_title', 'bbloomer_capitalize_single_prod_title', 9999, 2 );
function bbloomer_capitalize_single_prod_title( $post_title, $post_id ) {
if ( ! is_admin() && 'product' === get_post_type( $post_id ) ) {
$post_title = ucwords( strtolower( $post_title ) );
}
return $post_title;
}
Hi Rodolfo,
Thanks for your snippet. Exactly what I was looking for, something without a plugin. However it would be great if you could help me with a version which Capitalises the entire title and not just the first letters. Would really look forward to that.
Also, I was looking at doing the capitalise part for other sections as well, eg. Sidebar Titles, Product attribute filters and other woocommerce elements. Is there a script which could help me do that globally or element wise. Where probably I could just change the element ID for example?
Really looking forward.
Vaibhav, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!