Hi Julius,
That’s possible, with a filter!
I’ve made two versions, it’s up to you to decide which you’d like. Both are untested!
Version 1: Compatibility filter. It’s heavier, but will prevent theme issues where the title is output later than the meta tags.
add_filter( 'the_seo_framework_title_args', 'my_title_adjustments' );
/**
* Determine the title status.
*/
function my_title_adjustments( $args = array() ) {
if ( isset( $args['meta'] ) && $args['meta'] ) {
//* Cache and adjust filter, only when outputting meta tags.
add_filter( 'the_seo_framework_add_blogname_to_title', 'my_title_blogname_cache' );
add_filter( 'the_seo_framework_add_blogname_to_title', '__return_false' );
} else {
//* Otherwise, reset the filter.
add_filter( 'the_seo_framework_add_blogname_to_title', 'my_title_blogname_cache' );
}
return $args;
}
/**
* Caches the filter output.
*/
function my_title_blogname_cache( $current = true ) {
static $cache = null;
if ( isset( $cache ) )
return $cache
return $cache = $current;
}
Version 2: Straight to the point. Is fast, uses less memory but does not consider theme/plugin compatibility:
add_filter( 'the_seo_framework_title_args', 'my_title_adjustments' );
/**
* Determine the title status.
*/
function my_title_adjustments( $args = array() ) {
static $has_run = null;
if ( isset( $has_run ) )
return $args;
if ( isset( $args['meta'] ) && $args['meta'] ) {
//* Adjust filter, only when outputting meta tags.
add_filter( 'the_seo_framework_add_blogname_to_title', '__return_false' );
}
$has_run = true;
return $args;
}
Take a close look at the og:title
and twitter:title
output to see what’s going into the Facebook/Twitter crawler.
Please note that Facebook/Twitter might hold scrape data cache, so the title might not be updated directly when sharing.
I hope this helps! Have a great day!