Synced Pattern Shortcode
Adds a [synced_pattern] shortcode that prints a synced pattern (formerly reusable block) anywhere shortcodes work, such as classic widgets, page builders or theme files.
Opens WPIDE on
Code
add_shortcode( 'synced_pattern', function ( $atts ) {
static $depth = 0;
$atts = shortcode_atts( array( 'id' => 0 ), $atts, 'synced_pattern' );
$pattern = get_post( absint( $atts['id'] ) );
if ( ! $pattern || 'wp_block' !== $pattern->post_type || 'publish' !== $pattern->post_status || $depth > 2 ) {
return '';
}
$depth++;
$html = do_blocks( $pattern->post_content );
$depth--;
return $html;
} );
Notes
Example: [synced_pattern id="123"]. Find the ID in Appearance > Patterns by opening the pattern and checking the address bar.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.