Shortcodes Not Rendering In Patterns

[ad_1]

Yes, shortcodes are supported in WordPress patterns. However, the issue you’re experiencing with the ACF shortcode not rendering in your button pattern might be due to the fact that the pattern is not properly parsing the shortcode.

<?php echo do_shortcode('[acf field="button_text"]'); ?>

or You can use this

$button_text_shortcode = get_field('your_acf_field_for_button_shortcode');
echo do_shortcode($button_text_shortcode);

Thanks @sbser123!

I was able to get them to render with the following:

function render_acf_shortcodes_in_blocks( $block_content, $block ) {
    if ( has_shortcode( $block_content, 'acf' ) || has_shortcode( $block_content, 'acf_field' ) ) {
        $block_content = do_shortcode( $block_content );
    }
    return $block_content;
}
add_filter( 'render_block', 'render_acf_shortcodes_in_blocks', 10, 2 );

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer