Looking at the theme, it seems a bit overly complex in how it determines the hero title. If there's no override options in the theme (I didn't install it to check), there does appear to a mesmerize_header_title
filter you can hook into, it's apparently how they change the title on WooCommerce pages natively in the theme.
One thing to note is that there can be many categories on a post, so typically you'll only want to show the first one. We can use get_the_category()
to return an array of WP_Term
objects, and apply the first one to the header title filter:
add_filter('mesmerize_header_title', function($title){
if( is_single() ){
$categories = get_the_category();
$title = $categories[0]->name;
}
return $title;
});
You should be able to put this in the functions.php
file and be good to go.
I based this code off the /inc/woocommerce/woocommerce.php
file that contains the following:
add_filter('mesmerize_header_title', function ($title) {
if (mesmerize_is_page_template()) {
if (is_archive() && mesmerize_get_current_template() === "woocommerce.php") {
$title = woocommerce_page_title(false);
}
}
return $title;
});