Add filter to exclude post title context for product 'category' and 'tag' archives (but retain title context for search and product attribute)

would like to remove "category: " and "tag: " prefixes, but retain those for attribute and searches.

thanks!

add_filter('get_the_archive_title', function ($title) {
    if (is_product_category()) {
        $title = is_product_category('', false);
    } elseif (is_product_tag()) {
        $title = single_tag_title('', false);
    } elseif (is_author()) {
        $title = '<span class="vcard">' . get_the_author() . '</span>';
    }
    return $title;
});

what currently attempting with

Hey @floridaseating,

you should be able to use the bricks/element/settings hook.

add_filter( 'bricks/element/settings', function( $settings, $element ) {
    if ( $element->name === 'post-title' ) {
        $settings['context'] = ! is_product_category() && ! is_product_tag();
    }

    return $settings;
}, 10, 2 );

Let me know if that helps.

Best,

André

1 Like

hi @aslotta

this does not seem to work. do i keep the ‘add context’ toggled on alongside this code? i would like context disable for category and tag, but otherwise enabled.

Hey @floridaseating,

if you implement this hook correctly the setting in the UI should not matter at all. It’s overridden for every post title element.

How / where did you add this code? Can you please show your version?

Best,

André

@aslotta - via wpcodebox plugin with the following settings:

Hey @floridaseating,

would you mind sending me some temporary credentials via DM so I can have a look at your site?

Best,

André