SlideShare a Scribd company logo
1 of 42
Creating a custom block pattern plugin
Jeff McNear
https://plasterdog.com
https://webprosmeetup.org
jeff@plasterdog.com
847/849-7060
The Gutenberg editor is here to stay
• Block based editing is efficient and user friendly
• You can do most things with core blocks
• Structural blocks facilitate complex layouts
• The interface is consistently improving
• We can pick and choose which elements to use
You can build almost anything with the core
set of blocks
A quick (and opinionated) pass
through the default set of
Gutenberg blocks:
Text Group
• Most are related to typography
• Classic reverts to the old style
• Code is handy for some of us
• Tables are not for layout
Media Group
• HTML5 video & audio players
• Sophisticated image controls
• Easily embed files
Design Group
• Pre formatted buttons
• Container blocks
• Superior control over spacing
• Promotes the nesting of blocks
Widgets Group
• Kind of a hodge podge
• Custom HTML for in-line editing
• Some plugins that generate
shortcodes will not have a block
• Common queries and feeds
Theme Group
• Header elements
• Query loops
• Query loop components
• Full site editing features that can
be used in places where the
block editor is active
• More query loop components
• Archive components
• Login form
Embed Group
While there is justification for
adding supplemental blocks
and/or creating a custom block –
usually this will be an over-
complication
Many times, when you think you
would need a custom block, what
you really need is a configuration
of nested blocks
It only makes sense to make provisions for saving
block configurations for reuse in other places…
Reusable blocks are like Illustrator symbols
First assemble the group of blocks
Then save the group as a reusable block
Once saved there will be a ”reusable” tab
For some reason there is no link to “/wp-admin/edit.php?post_type=wp_block” Except for in this tab…
Via the “manage” link the reusable block can be edited like any
other post type
You can import & export reusable block JSON files
Each instance of a reusable block will reflect any changes made
in the “parent”
But any instance of a
reusable block can be
converted back to a
collection of “regular”
blocks
So that sort of works…
There has got to be a better way to insert preformatted sections
that are intended to be modified and edited
Block patterns are assembled groups of blocks that are
intended to be editable
There are dozens of patterns within 9 existing categories
Block patterns are for all intents and purposes page (or post)
template parts that you can use at will in any part of the site
that uses the block editor
More block patterns can be found at: https://wordpress.org/patterns/
But using these supplemental patterns is a little clunky –
• You need to copy and paste the pattern
• To effectively paste you need to be in code view
… and worst of all they won’t be saved in the block insertor
Unlike with reusable blocks, there has been no provision
to edit, export or import block patterns
There are a couple of block pattern builder plugins, but they
are not in wide use and do not have an export function either
But creating a bespoke plugin creating custom patterns is not
too difficult.
<?php
/**
* Plugin Name: Bill Murray Pattern
* Description: Bill Murray pattern demo
* Version: 1.05
* Author: Jeff McNear
*/
/**
* Register Custom Block Pattern Styles
*/
Name and describe the plugin
add_action('init', function() {
remove_theme_support('core-block-patterns');
});
This block of code will remove most of the core block
patterns
add_action('init', function() {
if (!function_exists('unregister_block_pattern'))
{
return;
}
unregister_block_pattern('core/two-buttons');
unregister_block_pattern('core/three-buttons');
});
This block of code will remove two specific block
patterns: two-buttons & three-buttons
There are some things that can be done to clean up the interface
(usually)
add_action('init', function() {
if (!function_exists('unregister_block_pattern_category'))
{ return; } unregister_block_pattern_category('buttons');
});
This block of code will remove the block category
“buttons”
Note:
Themes are increasingly including custom patterns and block pattern categories – this means that the snippets above
will only work when there is no contradiction in the theme
add_action('init', function() {
remove_theme_support('core-block-patterns');
});
This block of code will (usually) remove all of
the core block patterns
Organizing custom patterns in a custom category will make
things easier
register_block_pattern_category(
'bill',
array( 'label' => __( 'Bill Murray', 'bmp' ) )
);
This block of code will
create a new category
to supplement the
core group of
categories
Once these decisions are made it is time to define the new
patterns
add_action('init', function() {
if (!function_exists('register_block_pattern')) {
return;
}
Opens the function registering new
block patterns
}); Closes the function
The definitions for the new patterns are placed in this section
Each pattern is defined by five elements:
// starts the pattern
register_block_pattern(‘bmp/bill-murray-bio', [
'title' => __(Bill Murray Bio', ‘bmp'),
'keywords' => [Bill Murray, bio'],
'categories' => ['featured’ , ‘bill’],
'viewportWidth' => 1000,
'content' => " ",
]);
// ends the pattern
Register the pattern
Name the pattern
Relevant keywords
Relevant categories
Viewport width
Content*
*This is the “tricky” part
Ends the pattern
The most straight forward way to compose the
content section is to first build the assembled group of blocks
in the Gutenberg editor.
Note: it is best to draw
images from offsite sources
such as:
https://picsum.photos
https://holderjs.com
https://fillmurray.com
https://placekeanu.com
https://placekitten.com
https://placebear.com
https://placedog.net/
Switch to the code editor view and select the code:
<!-- wp:columns -->
<div class="wp-block-columns"><!-- wp:column {"width":"66.66%"} -->
<div class="wp-block-column" style="flex-basis:66.66%"><!-- wp:heading -->
<h2>A new Pattern</h2>
<!-- /wp:heading -->
<!-- wp:paragraph -->
<p>some descriptive text</p>
<!-- /wp:paragraph -->
<!-- wp:social-links -->
<ul class="wp-block-social-links"><!-- wp:social-link {"service":"facebook"} /-->
<!-- wp:social-link {"service":"youtube"} /-->
<!-- wp:social-link {"service":"twitter"} /-->
<!-- wp:social-link {"service":"linkedin"} /--></ul>
<!-- /wp:social-links --></div>
<!-- /wp:column -->
<!-- wp:column {"width":"33.33%"} -->
<div class="wp-block-column" style="flex-basis:33.33%"><!-- wp:image {"sizeSlug":"large"} -->
<figure class="wp-block-image size-large"><img src="https://www.fillmurray.com/g/400/400" alt=""/></figure>
<!-- /wp:image --></div>
<!-- /wp:column --></div>
<!-- /wp:columns -->
HTML markup contains strings
which need to be ”escaped” to
work properly here
This tool will make sure the escapes are correctly written:
https://onlinestringtools.com/escape-string
<!-- wp:columns -->
<div class="wp-block-columns"><!-- wp:column {"width":"66.66%"} -->
<div class="wp-block-column" style="flex-basis:66.66%"><!-- wp:heading -->
<h2>A new Pattern</h2>
<!-- /wp:heading -->
<!-- wp:paragraph -->
<p>some descriptive text</p>
<!-- /wp:paragraph -->
<!-- wp:social-links -->
<ul class="wp-block-social-links"><!-- wp:social-link {"service":"facebook"} /-->
<!-- wp:social-link {"service":"youtube"} /-->
<!-- wp:social-link {"service":"twitter"} /-->
<!-- wp:social-link {"service":"linkedin"} /--></ul>
<!-- /wp:social-links --></div>
<!-- /wp:column -->
<!-- wp:column {"width":"33.33%"} -->
<div class="wp-block-column" style="flex-basis:33.33%"><!-- wp:image {"sizeSlug":"large"} -->
<figure class="wp-block-image size-large"><img src="https://www.fillmurray.com/g/400/400" alt=""/></figure>
<!-- /wp:image --></div>
<!-- /wp:column --></div>
<!-- /wp:columns -->n
… and here is the result!
Once your plugin is installed and
activated you will have access to
your custom block pattern
Like any other block pattern once inserted each individual
block will remain completely editable
(in that instance)
Then you can change out the contents of each block within the
pattern for each specific use case
Questions?

More Related Content

Similar to Build and save your own Gutenberg Block Patterns

Web components - An Introduction
Web components - An IntroductionWeb components - An Introduction
Web components - An Introductioncherukumilli2
 
"Umbraco MVC - a journey of discovery" - Lotte Pitcher
"Umbraco MVC - a journey of discovery" - Lotte Pitcher"Umbraco MVC - a journey of discovery" - Lotte Pitcher
"Umbraco MVC - a journey of discovery" - Lotte Pitcherlottepitcher
 
BEM it! Introduction to BEM
BEM it! Introduction to BEMBEM it! Introduction to BEM
BEM it! Introduction to BEMVarya Stepanova
 
Improving your responsive workflow with style guides
Improving your responsive workflow with style guidesImproving your responsive workflow with style guides
Improving your responsive workflow with style guidesLuke Brooker
 
Introduction to-concrete-5
Introduction to-concrete-5Introduction to-concrete-5
Introduction to-concrete-5Ketan Raval
 
Introduction to-concrete-5
Introduction to-concrete-5Introduction to-concrete-5
Introduction to-concrete-5ketanraval
 
Highly Maintainable, Efficient, and Optimized CSS
Highly Maintainable, Efficient, and Optimized CSSHighly Maintainable, Efficient, and Optimized CSS
Highly Maintainable, Efficient, and Optimized CSSZoe Gillenwater
 
Joomla Beginner Template Presentation
Joomla Beginner Template PresentationJoomla Beginner Template Presentation
Joomla Beginner Template Presentationalledia
 
Iasi code camp 12 october 2013 shadow dom - mihai bîrsan
Iasi code camp 12 october 2013   shadow dom - mihai bîrsanIasi code camp 12 october 2013   shadow dom - mihai bîrsan
Iasi code camp 12 october 2013 shadow dom - mihai bîrsanCodecamp Romania
 
6 Special Howtos for Drupal
6 Special Howtos for Drupal6 Special Howtos for Drupal
6 Special Howtos for DrupalWingston
 
Drupaldelphia 2013 Presentation- Making Your Site more Friendly to Search Eng...
Drupaldelphia 2013 Presentation- Making Your Site more Friendly to Search Eng...Drupaldelphia 2013 Presentation- Making Your Site more Friendly to Search Eng...
Drupaldelphia 2013 Presentation- Making Your Site more Friendly to Search Eng...Anson Han
 
Magento mega menu extension
Magento mega menu extensionMagento mega menu extension
Magento mega menu extensionBun Danny
 
Expanding XPages with Bootstrap Plugins for Ultimate Usability
Expanding XPages with Bootstrap Plugins for Ultimate UsabilityExpanding XPages with Bootstrap Plugins for Ultimate Usability
Expanding XPages with Bootstrap Plugins for Ultimate UsabilityTeamstudio
 
Maintainable Frontend Development with BEM
Maintainable Frontend Development with BEMMaintainable Frontend Development with BEM
Maintainable Frontend Development with BEMVarya Stepanova
 
Introduction to BOOTSTRAP
Introduction to BOOTSTRAPIntroduction to BOOTSTRAP
Introduction to BOOTSTRAPJeanie Arnoco
 
The Joy of Subforms with Randy Carey
The Joy of Subforms with Randy CareyThe Joy of Subforms with Randy Carey
The Joy of Subforms with Randy Careyjdaychi
 

Similar to Build and save your own Gutenberg Block Patterns (20)

Web components - An Introduction
Web components - An IntroductionWeb components - An Introduction
Web components - An Introduction
 
Fewd week2 slides
Fewd week2 slidesFewd week2 slides
Fewd week2 slides
 
"Umbraco MVC - a journey of discovery" - Lotte Pitcher
"Umbraco MVC - a journey of discovery" - Lotte Pitcher"Umbraco MVC - a journey of discovery" - Lotte Pitcher
"Umbraco MVC - a journey of discovery" - Lotte Pitcher
 
BEM it! Introduction to BEM
BEM it! Introduction to BEMBEM it! Introduction to BEM
BEM it! Introduction to BEM
 
Improving your responsive workflow with style guides
Improving your responsive workflow with style guidesImproving your responsive workflow with style guides
Improving your responsive workflow with style guides
 
Introduction to-concrete-5
Introduction to-concrete-5Introduction to-concrete-5
Introduction to-concrete-5
 
Introduction to-concrete-5
Introduction to-concrete-5Introduction to-concrete-5
Introduction to-concrete-5
 
Atomic design
Atomic designAtomic design
Atomic design
 
Highly Maintainable, Efficient, and Optimized CSS
Highly Maintainable, Efficient, and Optimized CSSHighly Maintainable, Efficient, and Optimized CSS
Highly Maintainable, Efficient, and Optimized CSS
 
Joomla Beginner Template Presentation
Joomla Beginner Template PresentationJoomla Beginner Template Presentation
Joomla Beginner Template Presentation
 
Iasi code camp 12 october 2013 shadow dom - mihai bîrsan
Iasi code camp 12 october 2013   shadow dom - mihai bîrsanIasi code camp 12 october 2013   shadow dom - mihai bîrsan
Iasi code camp 12 october 2013 shadow dom - mihai bîrsan
 
Responsive web design
Responsive web designResponsive web design
Responsive web design
 
6 Special Howtos for Drupal
6 Special Howtos for Drupal6 Special Howtos for Drupal
6 Special Howtos for Drupal
 
Drupaldelphia 2013 Presentation- Making Your Site more Friendly to Search Eng...
Drupaldelphia 2013 Presentation- Making Your Site more Friendly to Search Eng...Drupaldelphia 2013 Presentation- Making Your Site more Friendly to Search Eng...
Drupaldelphia 2013 Presentation- Making Your Site more Friendly to Search Eng...
 
18. images in symfony 4
18. images in symfony 418. images in symfony 4
18. images in symfony 4
 
Magento mega menu extension
Magento mega menu extensionMagento mega menu extension
Magento mega menu extension
 
Expanding XPages with Bootstrap Plugins for Ultimate Usability
Expanding XPages with Bootstrap Plugins for Ultimate UsabilityExpanding XPages with Bootstrap Plugins for Ultimate Usability
Expanding XPages with Bootstrap Plugins for Ultimate Usability
 
Maintainable Frontend Development with BEM
Maintainable Frontend Development with BEMMaintainable Frontend Development with BEM
Maintainable Frontend Development with BEM
 
Introduction to BOOTSTRAP
Introduction to BOOTSTRAPIntroduction to BOOTSTRAP
Introduction to BOOTSTRAP
 
The Joy of Subforms with Randy Carey
The Joy of Subforms with Randy CareyThe Joy of Subforms with Randy Carey
The Joy of Subforms with Randy Carey
 

More from Plasterdog Web Design

More from Plasterdog Web Design (6)

Wordpress overview
Wordpress overviewWordpress overview
Wordpress overview
 
Pantheon basics
Pantheon basicsPantheon basics
Pantheon basics
 
Wordpress Security & Hardening Steps
Wordpress Security & Hardening StepsWordpress Security & Hardening Steps
Wordpress Security & Hardening Steps
 
Basic wordpress editing
Basic wordpress editingBasic wordpress editing
Basic wordpress editing
 
Youtube Basics
Youtube BasicsYoutube Basics
Youtube Basics
 
Wordpress multisite
Wordpress multisiteWordpress multisite
Wordpress multisite
 

Recently uploaded

Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 

Recently uploaded (20)

Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 

Build and save your own Gutenberg Block Patterns

  • 1. Creating a custom block pattern plugin Jeff McNear https://plasterdog.com https://webprosmeetup.org jeff@plasterdog.com 847/849-7060
  • 2. The Gutenberg editor is here to stay • Block based editing is efficient and user friendly • You can do most things with core blocks • Structural blocks facilitate complex layouts • The interface is consistently improving • We can pick and choose which elements to use
  • 3. You can build almost anything with the core set of blocks
  • 4. A quick (and opinionated) pass through the default set of Gutenberg blocks:
  • 5. Text Group • Most are related to typography • Classic reverts to the old style • Code is handy for some of us • Tables are not for layout
  • 6. Media Group • HTML5 video & audio players • Sophisticated image controls • Easily embed files
  • 7. Design Group • Pre formatted buttons • Container blocks • Superior control over spacing • Promotes the nesting of blocks
  • 8. Widgets Group • Kind of a hodge podge • Custom HTML for in-line editing • Some plugins that generate shortcodes will not have a block • Common queries and feeds
  • 9. Theme Group • Header elements • Query loops • Query loop components • Full site editing features that can be used in places where the block editor is active
  • 10. • More query loop components • Archive components • Login form
  • 12. While there is justification for adding supplemental blocks and/or creating a custom block – usually this will be an over- complication Many times, when you think you would need a custom block, what you really need is a configuration of nested blocks
  • 13. It only makes sense to make provisions for saving block configurations for reuse in other places…
  • 14. Reusable blocks are like Illustrator symbols First assemble the group of blocks Then save the group as a reusable block
  • 15. Once saved there will be a ”reusable” tab For some reason there is no link to “/wp-admin/edit.php?post_type=wp_block” Except for in this tab…
  • 16. Via the “manage” link the reusable block can be edited like any other post type
  • 17. You can import & export reusable block JSON files
  • 18. Each instance of a reusable block will reflect any changes made in the “parent” But any instance of a reusable block can be converted back to a collection of “regular” blocks
  • 19. So that sort of works…
  • 20. There has got to be a better way to insert preformatted sections that are intended to be modified and edited
  • 21. Block patterns are assembled groups of blocks that are intended to be editable There are dozens of patterns within 9 existing categories
  • 22. Block patterns are for all intents and purposes page (or post) template parts that you can use at will in any part of the site that uses the block editor
  • 23. More block patterns can be found at: https://wordpress.org/patterns/
  • 24. But using these supplemental patterns is a little clunky – • You need to copy and paste the pattern • To effectively paste you need to be in code view
  • 25. … and worst of all they won’t be saved in the block insertor
  • 26. Unlike with reusable blocks, there has been no provision to edit, export or import block patterns
  • 27. There are a couple of block pattern builder plugins, but they are not in wide use and do not have an export function either
  • 28. But creating a bespoke plugin creating custom patterns is not too difficult. <?php /** * Plugin Name: Bill Murray Pattern * Description: Bill Murray pattern demo * Version: 1.05 * Author: Jeff McNear */ /** * Register Custom Block Pattern Styles */ Name and describe the plugin
  • 29. add_action('init', function() { remove_theme_support('core-block-patterns'); }); This block of code will remove most of the core block patterns add_action('init', function() { if (!function_exists('unregister_block_pattern')) { return; } unregister_block_pattern('core/two-buttons'); unregister_block_pattern('core/three-buttons'); }); This block of code will remove two specific block patterns: two-buttons & three-buttons There are some things that can be done to clean up the interface (usually)
  • 30. add_action('init', function() { if (!function_exists('unregister_block_pattern_category')) { return; } unregister_block_pattern_category('buttons'); }); This block of code will remove the block category “buttons” Note: Themes are increasingly including custom patterns and block pattern categories – this means that the snippets above will only work when there is no contradiction in the theme add_action('init', function() { remove_theme_support('core-block-patterns'); }); This block of code will (usually) remove all of the core block patterns
  • 31. Organizing custom patterns in a custom category will make things easier register_block_pattern_category( 'bill', array( 'label' => __( 'Bill Murray', 'bmp' ) ) ); This block of code will create a new category to supplement the core group of categories
  • 32. Once these decisions are made it is time to define the new patterns add_action('init', function() { if (!function_exists('register_block_pattern')) { return; } Opens the function registering new block patterns }); Closes the function The definitions for the new patterns are placed in this section
  • 33. Each pattern is defined by five elements: // starts the pattern register_block_pattern(‘bmp/bill-murray-bio', [ 'title' => __(Bill Murray Bio', ‘bmp'), 'keywords' => [Bill Murray, bio'], 'categories' => ['featured’ , ‘bill’], 'viewportWidth' => 1000, 'content' => " ", ]); // ends the pattern Register the pattern Name the pattern Relevant keywords Relevant categories Viewport width Content* *This is the “tricky” part Ends the pattern
  • 34. The most straight forward way to compose the content section is to first build the assembled group of blocks in the Gutenberg editor. Note: it is best to draw images from offsite sources such as: https://picsum.photos https://holderjs.com https://fillmurray.com https://placekeanu.com https://placekitten.com https://placebear.com https://placedog.net/
  • 35. Switch to the code editor view and select the code: <!-- wp:columns --> <div class="wp-block-columns"><!-- wp:column {"width":"66.66%"} --> <div class="wp-block-column" style="flex-basis:66.66%"><!-- wp:heading --> <h2>A new Pattern</h2> <!-- /wp:heading --> <!-- wp:paragraph --> <p>some descriptive text</p> <!-- /wp:paragraph --> <!-- wp:social-links --> <ul class="wp-block-social-links"><!-- wp:social-link {"service":"facebook"} /--> <!-- wp:social-link {"service":"youtube"} /--> <!-- wp:social-link {"service":"twitter"} /--> <!-- wp:social-link {"service":"linkedin"} /--></ul> <!-- /wp:social-links --></div> <!-- /wp:column --> <!-- wp:column {"width":"33.33%"} --> <div class="wp-block-column" style="flex-basis:33.33%"><!-- wp:image {"sizeSlug":"large"} --> <figure class="wp-block-image size-large"><img src="https://www.fillmurray.com/g/400/400" alt=""/></figure> <!-- /wp:image --></div> <!-- /wp:column --></div> <!-- /wp:columns -->
  • 36. HTML markup contains strings which need to be ”escaped” to work properly here
  • 37. This tool will make sure the escapes are correctly written: https://onlinestringtools.com/escape-string
  • 38. <!-- wp:columns --> <div class="wp-block-columns"><!-- wp:column {"width":"66.66%"} --> <div class="wp-block-column" style="flex-basis:66.66%"><!-- wp:heading --> <h2>A new Pattern</h2> <!-- /wp:heading --> <!-- wp:paragraph --> <p>some descriptive text</p> <!-- /wp:paragraph --> <!-- wp:social-links --> <ul class="wp-block-social-links"><!-- wp:social-link {"service":"facebook"} /--> <!-- wp:social-link {"service":"youtube"} /--> <!-- wp:social-link {"service":"twitter"} /--> <!-- wp:social-link {"service":"linkedin"} /--></ul> <!-- /wp:social-links --></div> <!-- /wp:column --> <!-- wp:column {"width":"33.33%"} --> <div class="wp-block-column" style="flex-basis:33.33%"><!-- wp:image {"sizeSlug":"large"} --> <figure class="wp-block-image size-large"><img src="https://www.fillmurray.com/g/400/400" alt=""/></figure> <!-- /wp:image --></div> <!-- /wp:column --></div> <!-- /wp:columns -->n … and here is the result!
  • 39. Once your plugin is installed and activated you will have access to your custom block pattern
  • 40. Like any other block pattern once inserted each individual block will remain completely editable (in that instance)
  • 41. Then you can change out the contents of each block within the pattern for each specific use case