• Resolved kingchris

    (@kingchris)


    Hi,

    Are shortcodes not supported in patterns (synced or unsynced)? I created a button pattern that uses an ACF shortcode for the button text; however, it won’t render the shortcode on the front end. Any help is greatly appreciated! Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • 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);
    Thread Starter kingchris

    (@kingchris)

    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 );

    Hi @kingchris!

    In which php file should I put the code for the shortcodes to work in the patterns?

    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 );

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.