Support

Account

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 😎