Shortcode

Last updated May 22, 2024

Overview

Shortcodes can be used within a WYGIWYG to display another field’s value. To learn more about shortcodes, click here.

From ACF 6.3.0, the ACF shortcode is disabled by default for new installs of ACF. If you need to enable it, see enabling the ACF shortcode.

For security, we recommend disabling the ACF shortcode if you are not using it.

Usage

Place the shortcode marker with the desired field within your wysiwyg content. This shortcode runs the same as the the_field() function.

[acf field="field_name" post_id="123"]

Example

This is a story about a boy named [acf field="name"]. He is [acf field="age"] years old.

Limitations

  • Only works for simple text based values

Disabling the Shortcode

The ACF shortcode allows access to any field on any post type as was enabled by default any install of ACF created before the release of ACF 6.3. This means any user who has permission to publish posts on your site can view any ACF data if they know the field name or key. For this reason, we recommend you disable the shortcode if your site is not using it. You can use the following setting to disable it:

add_action( 'acf/init', 'set_acf_settings' );
function set_acf_settings() {
    acf_update_setting( 'enable_shortcode', false );
}

Enabling the Shortcode

When enabled, the ACF shortcode allows access to any field on any post type. This means any user who has permission to publish posts on your site can view any ACF data if they know the field name or key. For this reason, from ACF 6.3 the shortcode is disabled by default for new installs. If you do need to use it, for example for a page builder, you can use the following setting to enable it:

add_action( 'acf/init', 'set_acf_settings' );
function set_acf_settings() {
    acf_update_setting( 'enable_shortcode', true );
}