How to replace texts with values from ACF fields?

Dynamic Shortcode Values component allows you dynamically replace text with values from ACF fields. This feature is especially useful when you're creating template for one of your post types or taxonomy terms, where you have partially defined content, while other pieces of that text defined in posts or terms. Below is a simple example how to do this:

Step 1: Create ACF Field

The first thing you need is to create (if you don't have yet) some ACF field (or few) that you'll be using to replace text placeholders in your text field. On the image below you can see I've created a single ACF text field to contain a name I'm going to use as a replacement value.

Step 2: Set Value for ACF Field

Next you need you set some value for your ACF field. I'm going to set "John" for my "Name" field.

Step 3: Create Text With Placeholders

Now you're ready to create your dynamic text. Just add a regular Text Block in Visual Composer and write your text there. In places where you want your dynamic values to appear, add corresponding placeholders. A placeholder is just the same text, but written in the way that you can easily identify that it is a placeholder that should be replaced. In the example below, I'm going to write a simple text with just a single placeholder, I'll call it {acf_name}, so I can easily see that this piece will be replaced with the value from ACF.

Step 4: Configure Dynamic Values to Replace Placeholders with Values from ACF Fields

Finally, you need to setup Dynamic Values, so those placeholders you've added to the text content will be replaced with the values from ACF fields. In order to do so, click to edit your Text Block and go to the Dynamic Values tab. Click "Add New" to create a new replacement rule. On the left you need to pick "Custom text placeholder" and type your placeholder below. On the right, pick "Advanced Custom Fields" group, then find and select the field you need among available ACF Field Groups. On the image below, you can see I'm going to replace {acf_name} placeholder with ACF field Name.

End Result

The highlighted text below is the end result I got by accomplishing steps above.

Hello dear, my name is John!

Recent Posts