Skip to content

Instantly share code, notes, and snippets.

@seanlanglands
Last active July 21, 2022 09:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seanlanglands/74056e5b71e2814ea7035bd319209b64 to your computer and use it in GitHub Desktop.
Save seanlanglands/74056e5b71e2814ea7035bd319209b64 to your computer and use it in GitHub Desktop.
Example block pattern that's based on a cover block featuring move and remove locking attributes.
<?php
$default_attachment_url = get_stylesheet_directory_uri() . '/assets/images/default-cover-bg.jpg';
$block_pattern_content = '<!-- wp:cover {"url":"' . esc_url( $default_attachment_url ) . '","id":42,"dimRatio":90,"minHeight":0,"minHeightUnit":"px","gradient":"vivid-cyan-blue-to-vivid-purple","align":"full","style":{"spacing":{"padding":{"top":"5rem","right":"14rem","bottom":"5rem","left":"14rem"}}}} -->
<div class="wp-block-cover alignfull" style="padding-top:5rem;padding-right:14rem;padding-bottom:5rem;padding-left:14rem;min-height:0px">
<span aria-hidden="true" class="has-background-dim-90 wp-block-cover__gradient-background has-vivid-cyan-blue-to-vivid-purple-gradient-background has-background-dim has-background-gradient"></span>
<img class="wp-block-cover__image-background wp-image-42" alt="" src="' . esc_url( $default_attachment_url ) . '" data-object-fit="cover"/>
<div class="wp-block-cover__inner-container">
<!-- wp:heading {"textAlign":"center","level":4,"style":{"spacing":{"margin":{"top":"0","right":"0","bottom":"0","left":"0"}}},"textColor":"white","lock":{"remove":true,"move":true}} -->
<h4 class="has-text-align-center has-white-color has-text-color" style="margin-top:0;margin-right:0;margin-bottom:0;margin-left:0">
<strong>Ready to invest in content marketing?</strong>
</h4>
<!-- /wp:heading -->
<!-- wp:paragraph {"align":"center","textColor":"white"} -->
<p class="has-text-align-center has-white-color has-text-color">To explore more content trends and insights to level up your content marketing this year, we invite you to dive into our Content Matters 2022 Report.</p>
<!-- /wp:paragraph -->
<!-- wp:spacer {"height":"25px"} -->
<div style="height:25px" aria-hidden="true" class="wp-block-spacer"></div>
<!-- /wp:spacer -->
<!-- wp:buttons {"layout":{"type":"flex","justifyContent":"center"},"lock":{"remove":true,"move":true}} -->
<div class="wp-block-buttons">
<!-- wp:button {"backgroundColor":"black","textColor":"white","style":{"border":{"radius":"8px"}},"className":"is-style-fill","fontSize":"medium","lock":{"remove":true,"move":true}} -->
<div class="wp-block-button has-custom-font-size is-style-fill has-medium-font-size">
<a class="wp-block-button__link has-white-color has-black-background-color has-text-color has-background" style="border-radius:8px">Get a free copy of the report</a>
</div>
<!-- /wp:button -->
</div>
<!-- /wp:buttons -->
</div>
</div>
<!-- /wp:cover -->';
register_block_pattern(
'my-theme/cta-block-pattern',
[
'categories' => array( 'button' ),
'content' => $block_pattern_content,
'description' => _x( 'A block used for a call-to-action highlighting an external page.', 'Block pattern description', 'my-text-domain' ),
'keywords' => array( 'cta', 'call to action' ),
'title' => __( 'Article Call-to-Action', 'my-text-domain' ),
]
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment