Jun 05

Advanced Custom Fields – Shortcode

Ran into an issue where I wanted to create an interface where I could dynamically use the output of the ACF plugin within the pages, to allow a combination of the ACF and WSIWYG editor. I ended up creating the following function and adding it to ‘functions.php’ in my template:

/* Advanced Custom Fields Shortcode */
function get_acf( $atts ) {

    // Attributes
    $atts = shortcode_atts(
            'field' => '',

    // Return only if has field attribute
    if ( isset( $atts['field'] ) ) {
        //$field_value =
        return get_field($atts['field']);

add_shortcode( 'getacf', 'get_acf' );