Home » WooCommerce: Override Product Category Page Title

WooCommerce: Override Product Category Page Title

by Tutor Aspire

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 tutoraspire.com FREE
 * @author        Tutor Aspire
 * @compatible    WooCommerce 6
 * @donate $9     https://tutoraspire.com
 */

add_action( 'product_cat_add_form_fields', 'tutoraspire_add_category_alt_name' );

add_action( 'product_cat_edit_form_fields', 'tutoraspire_edit_category_alt_name' );
 
function tutoraspire_add_category_alt_name() { 
echo '
'; echo ''; echo ''; echo '
'; } function tutoraspire_edit_category_alt_name( $term ) { echo ''; echo 'Alternative title'; echo ''; echo ''; } add_action( 'edit_term', 'tutoraspire_save_category_alt_title', 10, 3 ); add_action( 'created_term', 'tutoraspire_save_category_alt_title', 10, 3 ); function tutoraspire_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', 'tutoraspire_edit_cat_page_title' ); function tutoraspire_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; }

You may also like