Skip to content
Advertisement

Shortcode from ACF Default Value only working after post is saved

I have this shortcode which is saved in the Default Value text field of an ACF field. The field type is Wysiwig editor.

I get the Default Value text by using acf_get_field('location_info')['default_value'] in my template file however the shortocde is only being processed after the post is opened and saved.

Before saving, the output is the shortcode itself.

So before saving: The quick brown [animal-name] jumps over…

And after saving the post: The quick brown fox jumps over…

The shortcode is generated through another plugin called ‘Insert PHP Code Snippet’.

The problem: how to get WP to process the shortcode without having to save the post first?

Advertisement

Answer

Wrap the method within do_shortcode() function to process the shortcodes in the text before echo the text to screen.

<?php echo do_shortcode(acf_get_field('location_info')['default_value']) ?>

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement