Home Forums ACF PRO Shortcodes stored within custom field values


Shortcodes stored within custom field values

  • For each post type, I have created several custom fields. One of the custom fields uses values stored in the other fields, so it includes HTML along with the [acf field=""] shortcode. For example, the custom field (called full_name) has a value of:
    <p>[acf field="first_name"] [acf field="last_name"]</p>

    When inserting the_field(‘full_name’) into single.php (or any other template file), it spits out the text verbatim instead of processing the shortcodes. I even tried do_shortcode(the_field(‘full_name’)) but that rendered nothing.

    Obviously I could simply use the_field(‘first_name’) the_field(‘last_name’), but each post has different field names.

    In short, is there a way that custom fields can process all shortcodes within their values upon use?

  • I don’t think it’s possible to do all that in one step…

    A couple things:
    You’d need to use get_field() instead of the_field(), and echo the do_shortcode() function. Then you’ll have to combine them both with the HTML:

    $first_name = get_field(‘first_name’);
    $last_name = get_field(‘last_name’);
    $shortcode = '<p>' . do_shortcode($first_name) . do_shortcode($last_name) . '</p>';
    echo $shortcode;
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Shortcodes stored within custom field values’ is closed to new replies.