This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

Reply To: Yoast title field

#34211
thewebco76thewebco76
Participant

This only replaced the title with the ID (you have $r->id in the filter)

But this pointed me to something useful – so thanks! Shared in case you ever need it for anyone else :

add_filter( 'asp_results', 'asp_force_yoast_title', 10, 1 );
function asp_force_yoast_title( $results ) {
	foreach ($results as $k => &$r ) {
		
		$r->title = apply_filters('the_title', $r->title);
		$newtitle = 'My Site Name Replacement';
		$realtitle = get_the_title($r->id);
		$r->title = str_replace( array("%%sitename%%","%%sep%%","%%title%%","%%page%%"), array($newtitle, " | ", $realtitle,""), "$r->title" );
		
	}
	
	return $results;
}
  • This reply was modified 4 years, 10 months ago by thewebco76thewebco76.