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!
βEver wondered when and why ACF uses JSON instead of the database? Check out our summary of the most recent session of ACF Chat Friday for the answer, and make sure to register for the next session.
— Advanced Custom Fields (@wp_acf) February 23, 2023
π https://t.co/3UtvQbDwNmhttps://t.co/wfFEVcXVKc
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.