Run Shortcodes Inside ACF Text Fields
Lets editors use shortcodes in ACF text and text area fields, which ACF otherwise prints as plain text.
Opens WPIDE on
Code
$wpide_acf_do_shortcodes = function ( $value ) {
return ( is_string( $value ) && false !== strpos( $value, '[' ) ) ? do_shortcode( $value ) : $value;
};
add_filter( 'acf/format_value/type=text', $wpide_acf_do_shortcodes, 20 );
add_filter( 'acf/format_value/type=textarea', $wpide_acf_do_shortcodes, 20 );
Notes
WYSIWYG fields already run shortcodes. Only use this if you trust everyone who can edit fields.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.