Home › Forums › Backend Issues (wp-admin) › ACF with custom Titles & Yoast SEO › Reply To: ACF with custom Titles & Yoast SEO
@lucpestille for that I think you would need to use the SEO hook for modifying the post title, but you’ll need to do a bit more checking
add_filter('wpseo_title', 'change_seo_title');
function change_seo_title($string) {
$queried_object = get_queried_object();
if (!isset($queried_object->ID ||
get_post_type($queried_object->ID) != 'your-post-type-here')) {
// bail early
return $string;
}
$related_post = get_field('post_object_field_name', $queried_object->ID);
if ($related_post) {
$title = get_the_title($related_post->ID);
$string .= ' - '.$title;
}
return $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.