Add ACF fields to caption

[ad_1]

I assume, with “ACF” you mean “Advanced Custom Fields”?

If this is the case, you should start with the documentation at https://www.advancedcustomfields.com/resources/get_field/.

The post ID required for get_field() is also passed to the caption filter.

So it may be something like this if you want to add the custom field content below the existing caption (untested, but the idea should be clear):


function my_lbwps_caption_caption($caption, $id)
{
    $fieldContent = get_field('my_field_name', $id);
    
    // Combine original caption and field content with a <br>
    return sprintf('%s<br>%s', $caption, $fieldContent);
}

add_filter('lbwps_caption_caption', 'my_lbwps_caption_caption', 10, 2);

`

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer