WooCommerce: Override Product Category Page Title

This is an interesting WooCommerce customization – as you know WordPress menus and widgets read whatever product category name and display it in the frontend.

Let’s say your product category title is “Tables”. This will show up in the navigation menu if you have set it up that way, in te breadcrumbs if you have any, in the sidebar category widgets, and as a title on the single product category page.

This is great and all, but what if your product category name is “Red Round Tables By Whatever Brandname“? As you can imagine, displaying this in a sidebar or navigation menu may be a little too much, while it’s fine to use it as a H1 on the single product category page for SEO reasons and enhanced readability.

So, the question is – how do we define an “alternative” product category name, so that this can be used on the product category page as custom title, while using the default one for other smaller locations such as menus and widgets?

Well, this is how it’s done – enjoy!

As you can see from this screenshot, I’ve assigned an alternative product category name of “Bloomer Armada: A Private Community for WooCommerce Developers” to the “Bloomer Armada” category. Now, the custom name appears as H1 on the single product category page, while the original name is preserved in the breadcrumbs, navigation menu items, sidebar widgets and product loop items.

PHP Snippet: “Alternative” Product Category Name

/**
 * @snippet       Second Category Title @ WooCommerce Product Category
 * @how-to        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @compatible    WooCommerce 6
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */

add_action( 'product_cat_add_form_fields', 'bbloomer_add_category_alt_name' );

add_action( 'product_cat_edit_form_fields', 'bbloomer_edit_category_alt_name' );
 
function bbloomer_add_category_alt_name() { 
	echo '<div class="form-field">';
	echo '<label for="ctitle">Alternative title</label>';
	echo '<input type="text" id="ctitle" name="ctitle">';
	echo '</div>';
}

function bbloomer_edit_category_alt_name( $term ) { 
	echo '<tr class="form-field">';
	echo '<th for="ctitle">Alternative title</th>';
	echo '<td><input type="text" id="ctitle" name="ctitle" value="' . get_term_meta( $term->term_id, 'ctitle', true ) . '"></td>';
	echo '</tr>';
}

add_action( 'edit_term', 'bbloomer_save_category_alt_title', 10, 3 );
add_action( 'created_term', 'bbloomer_save_category_alt_title', 10, 3 );
 
function bbloomer_save_category_alt_title( $term_id, $tt_id = '', $taxonomy = '' ) {
	if ( 'product_cat' !== $taxonomy ) return;
	if ( isset( $_POST['ctitle'] ) ) {
		update_term_meta( $term_id, 'ctitle', $_POST['ctitle'] );
	} else {
		update_term_meta( $term_id, 'ctitle', '' );
	}
}

add_filter( 'woocommerce_page_title', 'bbloomer_edit_cat_page_title' );
 
function bbloomer_edit_cat_page_title( $title ) {
   if ( is_product_category() ) {
	   $term = get_queried_object();
	   $title = get_term_meta( $term->term_id, 'ctitle', true ) ? get_term_meta( $term->term_id, 'ctitle', true ) : $title;
   }
   return $title;
}

Where to add custom code?

You should place custom PHP in functions.php and custom CSS in style.css of your child theme: where to place WooCommerce customization?

This code still works, unless you report otherwise. To exclude conflicts, temporarily switch to the Storefront theme, disable all plugins except WooCommerce, and test the snippet again: WooCommerce troubleshooting 101

Related content

  • WooCommerce: Add Second Description @ Product Category Pages
    In terms of SEO, if you’re trying to rank your product category pages, you really need to make the most of the default WooCommerce product category “description” and “thumbnail”. Most themes, if compatible with WooCommerce, will show this content right below the product category name and above products. Nothing new so far. But what if […]
  • WooCommerce: Exclude Category from ‘product_categories’ Shortcode
    Sometimes solutions are very simple, and you don’t need rocket science to fix your issue! A client of mine needed to hide a category from the Product Categories Shortcode ( BloomerArmada (1) WooCommerce Mini-Plugins (25) ); in fact, there is no parameter that allows you to “exclude” a given product category such as “uncategorized” or […]
  • WooCommerce: Display Product Categories @ Cart & Checkout Pages
    While working for a freelance client I had to “detect” the cart item categories in order to apply some PHP customization. So I thought – why not share with you how to display product categories in the Cart and Checkout? This adds a nice touch to those two vital pages, and prints a list of […]
  • WooCommerce: Should I Noindex Product Tag Pages?
    Ah, yet another million dollar question. If you have organized your WooCommerce products properly, you have “N” product categories and “M” product tags, where “M > N” (actually, if there were such a thing in algebra, it should be “M >>> N” as each product should be assigned to 1 category and multiple tags). This […]
  • WooCommerce: Edit “Add to Cart” Text by Product Category
    Today we take a look at the WooCommerce “Add to Cart” buttons. What if you wanted to change the “Add to Cart” text depending on the Product Category? For example, you may want to show “Buy Now” for books and “Add to Basket” for cds.

Rodolfo Melogli

Business Bloomer Founder

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza. Follow @rmelogli

13 thoughts on “WooCommerce: Override Product Category Page Title

  1. Hi – many thanks for this!

    Just what I was looking for, but how do I get an alternative title to also be displayed and not just be in the HTML code?

    ie ‘Breadcrumb category title ‘Alexandra Theatre’ (and internal links display this)
    (displayed as the H1 page title on the product Category Page)
    ‘Alexandra Theatre Shows Booking Now’

    1. Sorry Neil, not sure I follow?

  2. very good
    I always used your nice functions.
    How can I use this code also for the tag? Both product categories and product tags.

    1. Thank you! This is not too difficult, just change any “product_cat” to “product_tag”, and “is_product_category” with “is_product_tag”. Good luck!

      1. Yes it worked properly, thank you again

  3. Hi Rodolfo, you have been a savior to us many times. We however have a specific Q. We want to replace the term_title (product_cat, product_tag, both) with a function. We could replace the product_title by using “add_filter(‘the_title’, ‘custom_function’)”. How can we accomplish the same for the term_title?

    1. Hello Ravi, not sure I follow. Does this snippet work for you?

  4. Hello. I would like to ask you how can i keep both titles. I need one Name title and after that the alternative title. Thanks in advance.

    1. Of course! Just replace the last snippet with this:

      add_filter( 'woocommerce_page_title', 'bbloomer_edit_cat_page_title' );
        
      function bbloomer_edit_cat_page_title( $title ) {
         if ( is_product_category() ) {
            $term = get_queried_object();
            $title .= get_term_meta( $term->term_id, 'ctitle', true ) ? get_term_meta( $term->term_id, 'ctitle', true ) : '';
         }
         return $title;
      }
      

      You may also need to wrap the second title in an HTML tag in order to send it to the following line

  5. Can we do this for breadcrumbs?

    1. Hi Mustafa, 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!

  6. Thank you for this one, this really is a problem in some categories. Very helpful. Can’t wait to see more! ­čÖé

Questions? Feedback? Customization? Leave your comment now!
_____

If you are writing code, please wrap it like so: [php]code_here[/php]. Failure to complying with this, as well as going off topic or not using the English language will result in comment disapproval. You should expect a reply in about 2 weeks - this is a popular blog but I need to get paid work done first. Please consider joining the Business Bloomer Club to get quick WooCommerce support. Thank you!

Your email address will not be published. Required fields are marked *