Hello!
I believe breadcrumbs convey better to the visitor which category is used.
Nevertheless, I think this should do (untested):
add_filter( 'the_seo_framework_title_from_generation', function( $title, $args ) {
static $sep;
// PHP 7.4:
// $sep ??= the_seo_framework()->get_title_separator();
// PHP 7.2+
$sep = $sep ?? the_seo_framework()->get_title_separator();
if ( null === $args ) {
$category = the_seo_framework()->is_singular() ? get_the_category() : null;
} else {
$category = empty( $args['taxonomy'] ) ? get_the_category( $args['id'] ) : '';
}
$cat_name = $category[0]->name ?? '';
if ( $cat_name ) {
$title .= " $sep $cat_name";
}
return $title;
}, 10, 2 );
We’re moving to require PHP 7.2+ in the next release, so I might as well provide snippets that need it already.
Please remember that the title input field is unaware of this change and may display something other than what you see on the front-end.