Home › Forums › Backend Issues (wp-admin) › ACF with custom Titles & Yoast SEO › Reply To: ACF with custom Titles & Yoast SEO
Excellent – worked almost straight out of the box – thanks a million. For anyone else who needs it, my final code was;
function change_seo_title($string) {
$queried_object = get_queried_object();
if ( !isset($queried_object->ID) || get_post_type($queried_object->ID) != 'post' ) {
// bail early
return $string;
}
$related_post = get_field('product', $queried_object->ID);
if ($related_post) {
$related_post_title = get_the_title($related_post->ID);
$new_title = $related_post_title . " - " . $string;
}
return $new_title;
}
add_filter('wpseo_title', 'change_seo_title');
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.