Advanced Custom Fields (ACF) is an awesome plugin for WordPress users to easily add custom fields to posts, pages, or templates. But, when you use ACF shortcodes in Full Site Editing (FSE) themes, you’ll face problems for some reason. In this post, we will discuss the issues and solutions for the ACF shortcode not working and how to enable ACF shortcode.
Why the ACF Shortcode is Disabled on this Site?
The most common reason for the ACF shortcode not working is that we are using an updated version (which is always good), and for RankTiS, we are also using the Full Site Editing Theme. For the older version, everything was well but with some security issues.
ACF has updated security measures, from ACF 6.3.0, the ACF shortcode is disabled by default for new installs of the ACF WordPress plugin (mentioned here). However, block-based FSE themes have another problem with meta fields and custom fields in block templates. The solution is straightforward with simple code snippets without adding another plugin.
To ensure ACF shortcodes work correctly with the updated version and within the WordPress FSE theme, we must add some codes (functions) in the child theme’s function.php or a custom code snippet plugin. Below are the steps to follow:
Enable ACF Shortcode Features with Updated Version
Add the below code to your function.php or in a custom code snippet plugin like WP Code or others.
// Enabling ACF Shortcode Features
add_action( 'acf/init', 'set_acf_settings' );
function set_acf_settings() {
acf_update_setting( 'enable_shortcode', true );
}
Allow ACF Shortcode in FSE WordPress Templates
Now, we need to add this filter to allow ACF shortcodes to function properly outside of the traditional post-content areas, such as in block-based full-site editing FSE templates. If you are not using Full Site Editing theme then you do not need the below code, only the above code is ok for you.
// Enabling ACF for FSE Theme Templates
add_filter('acf/shortcode/allow_in_block_themes_outside_content', '__return_true');
Use ACF Shortcode as Before without an Extra Plugin
Once the above settings are configured, we can start using ACF shortcodes directly within block templates. This shortcode is an example of how to use an ACF shortcode in a template part or block. Replace “custom_field_name_here” with the actual name of the ACF field you want to display.
[acf field="custom_field_name_here"]
Example Use Case of ACF Shortcodes in FSE Theme
Let’s say you have a custom field featured_text that you want to display in the header of your site. Here’s how you would do it:
- Edit Your FSE Header Template:
- Go to the WordPress Site Editor.
- Navigate to the template part where you want to display the field (e.g., Header).
- Add a Shortcode Block:
- Add a “Shortcode” block within the desired location in your header.
- Insert the shortcode.
- Save and Preview:
- Save your changes and preview your site to ensure it is displayed correctly.
By following these simple steps, you can effectively resolve any issues with ACF shortcodes in WordPress FSE themes. This solution allows you to continue using ACF’s powerful custom fields within the modern, block-based framework of FSE, ensuring your site remains dynamic and customizable.
Further Considerations When Enabling Shortcodes
- Security: Always ensure your code and ACF fields are secure, especially if you’re enabling features that were disabled by default. For security, they recommend disabling the ACF shortcode if you are not using it.
- Testing: After implementing these changes, thoroughly test your site to ensure that all shortcodes work as expected across different templates and devices. If the ACF shortcode not working till now, please contact their support.
Disabling the Shortcode: The ACF shortcode allows access to any field on any post type as was enabled by default in any install of ACF created before the release of ACF 6.3. This means that any user with permission to publish posts on your site can access any ACF data if they know the field name or key. As a result, they recommend turning off the shortcode if the site is not using it. We can keep it disabled with below code:
add_action( 'acf/init', 'set_acf_settings' );
function set_acf_settings() {
acf_update_setting( 'enable_shortcode', false );
}
Additional Resources that Help
Contact RankTiS for Your WordPress Needs
Are you looking for tailored WordPress solutions or a custom FSE theme for your business or agency? At RankTiS, we specialize in delivering high-quality WordPress services, including:
- Custom WordPress Theme Development
- Bespoke Full Site Editing (FSE) Themes
- WordPress Websites Without Third-Party Plugins
- AMP Solutions for WordPress
- AMP-Optimized WordPress Website Design
- WordPress Website Speed Optimization
- & More…
Whether you need a unique theme, optimized performance, or expert guidance on AMP, our team is here to help. Contact us today to discuss your project and see how we can bring your vision to life!
