Using Shortcodes in Advanced Custom Fields (ACF) Plugin

WordPressWant 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.

Incoming search terms:

  • https://yandex ru/clck/jsredir?from=yandex ru;search;web;;&text=&etext=1835 WC5HgiF56e3oip58CtKNVpGnkp6prBUGhFs0mUVGjKp9aV1aH5sKa5yz23pyMo5L 78d03606311461e8e832c72f5fb71ea7d742bf1c&uuid=&state=_BLhILn4SxNIvvL0W45KSic66uCIg23qh8iRG98qeIXme

Comments

  1. By bluefishsign

    Reply

Leave a Reply

Your email address will not be published.