# 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.

- Type: PHP
- Runs: Run everywhere
- Category: [Block Editor](https://wpide.com/library/category/gutenberg/)
- Tags: patterns, shortcode, reusable-blocks
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/synced-pattern-shortcode/

## Code

```php
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 use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Synced Pattern Shortcode" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
