Block patterns in WordPress are one of the latest functionality extensions that aim to make it easier to create attractive websites. Thanks to block patterns, users can assemble complex page layouts from ready-made blocks, instead of building them from scratch. The patterns are available in a variety of categories and styles, such as headlines, about us sections, team sections, testimonial sections, and more.
1. Using built-in WordPress block patterns
WordPress 5.5 introduced the concept of block patterns, which are available in the Gutenberg block editor. When you create a new post or page, you can browse and select from the predefined patterns that are available in the patterns section of the block editor.
To use these patterns:
- Przejdź do strony „Dodaj nowy” lub „Edytuj” w panelu administracyjnym WordPress.
- Kliknij ikonę „Dodaj blok” (plus w górnym lewym rogu edytora).
- Przełącz się na kartę „Wzorce” i wybierz wzór, który chcesz dodać do swojej strony.
2. Create your own block patterns
Did you know you can create your own block patterns? This can be done using PHP code.
Below is a sample code snippet you can add to your theme's functions.php file:
register_block_pattern( 'your-theme/pattern-name', array( 'title' => __( 'Pattern name', 'your-theme' ), 'categories' => array( 'category' ), 'description' => _x( 'Pattern description', 'Block description', 'your-theme' ), 'content' => "<!-- wp:paragraph -->\n<p>" . __( 'Block content', 'your-theme' ) ."</p>\n<!-- /wp:paragraph -->",
)
);
W tym przykładzie 'twoj-motyw/nazwa-wzoru’ to unikalny identyfikator dla wzoru bloku, a 'content’ zawiera zawartość wzoru bloku. Kategorie określają, gdzie wzór będzie wyświetlany w edytorze bloków.
3. Using plugins to manage block patterns
Innym podejściem jest użycie wtyczek do zarządzania wzorcami bloków. Jedną z najpopularniejszych jest „Block Pattern Builder”.
This plugin allows you to create patterns directly from the block editor, which is much easier for people not familiar with PHP. After installing and activating the plugin, you can create, edit and delete block patterns as if they were normal entries.
4. Importing and exporting block patterns
Możesz również chcieć importować i eksportować wzorce bloków między różnymi stronami WordPress. Do tego celu można użyć wtyczki „Block Pattern Importer/Exporter”.
This plugin allows you to export patterns to a JSON file which can then be imported to another WordPress site. This is especially useful when you want to use the same patterns on multiple pages.
WordPress block patterns make it much easier to create attractive websites. Thanks to built-in templates, the ability to create your own templates, and template management plugins, we have at our disposal a powerful tool for building unique and personalized websites.