If you’ve tried adding an ACF (Advanced Custom Fields) shortcode inside a Divi Text Module or Code Module, you may have noticed that it doesn’t always work. This is because Divi doesn’t natively execute ACF shortcodes the way it does with standard WordPress shortcodes.
Worry not! There’s an easy solution around that!
Instead of relying on Divi’s built-in functionality, we can create a custom shortcode that allows ACF fields to work inside Divi modules.
Let’s create a new shortcode called [acf_field].
Add this PHP code to your child theme’s functions.php file:
function get_acf_field_shortcode($atts) {
$atts = shortcode_atts(array(
'field' => '',
'post_id' => get_the_ID()
), $atts);
if (!empty($atts['field'])) {
return get_field($atts['field'], $atts['post_id']);
}
return '';
}
add_shortcode('acf_field', 'get_acf_field_shortcode');
Use the Custom Shortcode in Divi
Now that your shortcode is ready, you can use it inside Divi modules to display the ACF field data you need. For example if your ACF name is price you can display it in a Divi Text Module using the following:
The price is: [acf_field field="price"]€
Just replace “price” with the actual ACF field name you want to display and you’re done!
This happens because Divi doesn’t always execute ACF shortcodes, but it does execute shortcodes registered in functions.php!
Try it out and let me know if you have any questions!