// ===== CW: Fix blog post title tags (remove trailing separator, add site name) =====
// Titles were "Post Title -" — separator showing without site name after it.
// Root cause: Yoast title template for posts has %%sep%% %%sitename%% but sitename
// in wpseo_titles was empty. Fix: set it + remove stray trailing separator via filter.
add_action( 'init', function () {
if ( get_transient( 'cw_insights_title_fix_v1' ) ) return;
$opt = get_option( 'wpseo_titles', array() );
// Ensure site name is set
if ( empty( $opt['website_name'] ) ) {
$opt['website_name'] = 'Codewave';
}
// Ensure post title template includes site name
if ( empty( $opt['title-post'] ) || strpos( $opt['title-post'], '%%sitename%%' ) === false ) {
$opt['title-post'] = '%%title%% %%sep%% %%sitename%%';
}
update_option( 'wpseo_titles', $opt );
set_transient( 'cw_insights_title_fix_v1', 1, 0 );
} );
// Belt-and-suspenders: strip any trailing " -" or " | " left by missing variable
add_filter( 'wpseo_title', function ( $title ) {
return preg_replace( '/s*[-|]+s*$/', '', $title );
} );
// ===== END CW: Fix blog post title tags =====
Karthik Ramesh is a Product Manager at Codewave who bridges business goals and technology delivery. His writing covers product strategy, technology adoption, and the frameworks Codewave uses to help clients define, build, and scale digital products—bringing a business-first lens to digital innovation.