Using Shortcodes in Advanced Custom Fields (ACF) Plugin
Want to know what one of the best plugins for WordPress is? Advanced Custom Fields.
It allows you to create custom fields for your layout easily and transform the interface as you see fit. And the best part? It’s easily implemented through code.
Generally, I use this plugin to add simple extra fields to specific template types or pages. For example, if you make a custom theme that has a subtitle under the header, you can easily add a textbox for that. What if you want your client to be able to easily change the color of the header or subheader? Add a dropdown of predefined colors OR even a color picker!
Something I hadn’t needed to do before (but obviously needed to do today), was allow for shortcodes to be used in a custom textbox. It was easily achieved by using apply_filters like so:
<?php //Get the field like normal $fielddata = get_field('textbox_field'); //Apply filter to initiate shortcodes $fielddata = apply_filters('the_content', $fielddata); ?>
That’s it! You can just echo it on the page afterward.
Just what I needed. Thanks!