Last active
August 24, 2020 17:33
-
-
Save karks88/a117ddd08960c915ef6a35846ecb75d7 to your computer and use it in GitHub Desktop.
Creating a custom Gutenberg block pattern for WordPress.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: My WP Custom Block Patterns | |
Description: Adds a custom block pattern to the Gutenberg block editor. | |
Version: 1.0 | |
Author: Eric Karkovack | |
Author URI: https://www.speckyboy.com | |
*/ | |
function my_custom_wp_block_patterns() { | |
register_block_pattern( | |
'page-intro-block/my-custom-pattern', | |
array( | |
'title' => __( 'Page Intro Blocks', 'page-intro-block' ), | |
'description' => _x( 'Includes a cover block, two columns with headings and text, a separator and a single-column text block.', 'Block pattern description', 'page-intro-block' ), | |
'content' => "<!-- wp:cover -->\n<div class=\"wp-block-cover has-background-dim\"><div class=\"wp-block-cover__inner-container\"></div></div>\n<!-- /wp:cover -->\n\n<!-- wp:columns -->\n<div class=\"wp-block-columns\"><!-- wp:column -->\n<div class=\"wp-block-column\"><!-- wp:heading -->\n<h2>Heading</h2>\n<!-- /wp:heading -->\n\n<!-- wp:paragraph -->\n<p>Content Area #1</p>\n<!-- /wp:paragraph --></div>\n<!-- /wp:column -->\n\n<!-- wp:column -->\n<div class=\"wp-block-column\"><!-- wp:heading -->\n<h2>Heading</h2>\n<!-- /wp:heading -->\n\n<!-- wp:paragraph -->\n<p>Content Area #2</p>\n<!-- /wp:paragraph --></div>\n<!-- /wp:column --></div>\n<!-- /wp:columns -->\n\n<!-- wp:separator {\"className\":\"is-style-wide\"} -->\n<hr class=\"wp-block-separator is-style-wide\"/>\n<!-- /wp:separator -->\n\n<!-- wp:paragraph -->\n<p>Content Area #3</p>\n<!-- /wp:paragraph -->", | |
'categories' => array('header'), | |
) | |
); | |
} | |
add_action( 'init', 'my_custom_wp_block_patterns' ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Escaped HTML Code, thanks to https://codebeautify.org/json-escape-unescape --> | |
<!-- wp:cover -->\n<div class=\"wp-block-cover has-background-dim\"><div class=\"wp-block-cover__inner-container\"></div></div>\n<!-- /wp:cover -->\n\n<!-- wp:columns -->\n<div class=\"wp-block-columns\"><!-- wp:column -->\n<div class=\"wp-block-column\"><!-- wp:heading -->\n<h2>Heading</h2>\n<!-- /wp:heading -->\n\n<!-- wp:paragraph -->\n<p>Content Area #1</p>\n<!-- /wp:paragraph --></div>\n<!-- /wp:column -->\n\n<!-- wp:column -->\n<div class=\"wp-block-column\"><!-- wp:heading -->\n<h2>Heading</h2>\n<!-- /wp:heading -->\n\n<!-- wp:paragraph -->\n<p>Content Area #2</p>\n<!-- /wp:paragraph --></div>\n<!-- /wp:column --></div>\n<!-- /wp:columns -->\n\n<!-- wp:separator {\"className\":\"is-style-wide\"} -->\n<hr class=\"wp-block-separator is-style-wide\"/>\n<!-- /wp:separator -->\n\n<!-- wp:paragraph -->\n<p>Content Area #3</p>\n<!-- /wp:paragraph --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- This is the raw output of a set of custom blocks. It must be escaped in order to be used with the WordPress Block Pattern API. --> | |
<!-- wp:cover --> | |
<div class="wp-block-cover has-background-dim"><div class="wp-block-cover__inner-container"></div></div> | |
<!-- /wp:cover --> | |
<!-- wp:columns --> | |
<div class="wp-block-columns"><!-- wp:column --> | |
<div class="wp-block-column"><!-- wp:heading --> | |
<h2>Heading</h2> | |
<!-- /wp:heading --> | |
<!-- wp:paragraph --> | |
<p>Content Area #1</p> | |
<!-- /wp:paragraph --></div> | |
<!-- /wp:column --> | |
<!-- wp:column --> | |
<div class="wp-block-column"><!-- wp:heading --> | |
<h2>Heading</h2> | |
<!-- /wp:heading --> | |
<!-- wp:paragraph --> | |
<p>Content Area #2</p> | |
<!-- /wp:paragraph --></div> | |
<!-- /wp:column --></div> | |
<!-- /wp:columns --> | |
<!-- wp:separator {"className":"is-style-wide"} --> | |
<hr class="wp-block-separator is-style-wide"/> | |
<!-- /wp:separator --> | |
<!-- wp:paragraph --> | |
<p>Content Area #3</p> | |
<!-- /wp:paragraph --> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment