Advanced Custom Fields Extended Shortcode

Below, you’ll find a detailed guide on how to add the Advanced Custom Fields: Extended Shortcode to your WordPress website, including its parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Advanced Custom Fields: Extended Plugin shortcode not to show or not to work correctly.

Before starting, here is an overview of the Advanced Custom Fields: Extended Plugin and the shortcodes it provides:

Plugin Icon
Advanced Custom Fields: Extended

"Advanced Custom Fields: Extended is a powerful WordPress plugin that enhances your website's custom fields. It offers advanced features like bidirectional relationships, post type selection, and more."

★★★★☆ (126) Active Installs: 80000+ Tested with: 6.3.2 PHP Version: 5.6
Included Shortcodes:
  • [acfe_form]

Advanced Custom Fields: Extended [acfe_form] Shortcode

The ACF Extended plugin shortcode, ‘acfe_form’, is designed to render forms dynamically. It accepts an array of attributes, allowing customization of form and field attributes. This shortcode decodes the attributes, checks for sub-array compatibility, and sets the attributes array accordingly. It then initiates output buffering, renders the form using the attributes, and returns the buffered output. This ensures the form is displayed correctly on the front-end.

Shortcode: [acfe_form]

Examples and Usage

Basic Example – The shortcode displays a form using the ID attribute. This is a simple usage example that will render the form associated with the given ID.

[acfe_form id="1" /]

Advanced Examples

Here, the shortcode is used to display a form by referencing both the ID and title. The form will first try to load by ID, but if not found, it will try to load by title.

[acfe_form id="1" title="Contact Form" /]

In this example, additional attributes are added to customize the form’s HTML attributes. These attributes include class, id, and style. The form will be rendered with these HTML attributes.

[acfe_form id="1" form_attributes_class="my-form" form_attributes_id="my-form-id" form_attributes_style="background-color: #f9f9f9;" /]

This example shows a form with field attributes. This allows for customization of individual fields within the form. The ‘name’ field in this example will be rendered with the specified class and style.

[acfe_form id="1" fields_attributes_name_class="my-field" fields_attributes_name_style="color: #333;" /]

PHP Function Code

In case you have difficulties debugging what causing issues with [acfe_form] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('acfe_form',                          array($this, 'render_shortcode'));

Shortcode PHP function:

function render_shortcode($atts){
        // attributes array
        $atts = acf_get_array($atts);
        // allow array atts
        foreach(array_keys($atts) as $key){
            // sub array compatibility
            foreach(array('form_attributes_', 'fields_attributes_') as $allowed){
                // check found allowed
                if(!acfe_starts_with($key, $allowed)) continue;
                // explode
                $explode = explode($allowed, $key);
                $sub_key = $explode[1];
                // set attributes array
                $atts[ substr($allowed, 0, -1) ][ $sub_key ] = $atts[ $key ];
                unset($atts[ $key ]);
        // render
        return ob_get_clean();

Code file location:



Now that you’ve learned how to embed the Advanced Custom Fields: Extended Plugin shortcode, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.


Leave a Reply

Your email address will not be published. Required fields are marked *