Site logo

Archived topic

Category Names & Breadcrumbs

4 replies · Started by Ash on June 29, 2020

Viewing posts 1–5 of 5

Not exactly theme related but I can't find anything online. So I have changed my product category names to include keywords, but they are also added to woo breadcrumbs and don't look right. Also changes the the menu but I can just change the navigation labels for that. So any idea how I could accomplish this? I know I can use a function to replace them but I have over 140 categories :(

Hi there,

tricky one as all those elements will be using the_title function - and filtering that for specific needs is not easy.

Is the Keyword manually added to the title ?

Yes, maybe need to add a custom category field somehow, add it via a hook and then disable title.

Right sorted it. Just for anyone that may need to know in the future;

Used plugin Advanced Custom Fields
Add New > Name it 'Product category title'
Create Field > Name it 'Category title'
Location > Taxonomy - is equal to _ product_cat
Save, go and edit category, at bottom add custom title to the new field, hit save.

Add following code to functions.php

/*custom category titles*/
add_filter( 'woocommerce_page_title', 'custom_title' );
function custom_title( $page_title ) {
    if ( ! function_exists('get_field') || is_search() )
        return $page_title;

    if ( is_tax() ) {
        $term   = get_queried_object();
        $the_id = $term->taxonomy . '_' . $term->term_id;
    } elseif ( is_shop() ) {
        $the_id = wc_get_page_id( 'shop' );
    }
    return get_field( "category_title", $the_id ) ? get_field( "category_title", $the_id ) : $page_title;
}

Thats great - thanks for sharing :)

This archived topic is closed to new replies.