Home › Forums › Front-end Issues › ACF Fields in page title › Reply To: ACF Fields in page title
Hi
Have you tried the the_title
filter? this filter allows your to do something to the post title before it’s returned.
https://codex.wordpress.org/Plugin_API/Filter_Reference/the_title
So, your code would look something like:
add_filter('the_title', 'maybe_use_premium_acf_title', 15, 2);
function maybe_use_premium_acf_title($title, $post_id) {
// if it's not the cpt single, then don't do no nothing
if (! is_singular('your_post_type')) {
return $title;
}
// if 'hide_details' is not checked, then don't do no nothing either
if (! get_field('hide_details')) {
return $title;
}
return get_field('premium_title_field_name');
}
Cheers 😎
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.