SlideShare une entreprise Scribd logo
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?

Contenu connexe

Similaire à Build and save your own Gutenberg Block Patterns

Web components - An Introduction
Web components - An IntroductionWeb components - An Introduction
Web components - An Introduction
cherukumilli2
 
Fewd week2 slides
Fewd week2 slidesFewd week2 slides
Fewd week2 slides
William Myers
 
"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
lottepitcher
 
BEM it! Introduction to BEM
BEM it! Introduction to BEMBEM it! Introduction to BEM
BEM it! Introduction to BEM
Varya 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 guides
Luke Brooker
 
Introduction to-concrete-5
Introduction to-concrete-5Introduction to-concrete-5
Introduction to-concrete-5
ketanraval
 
Introduction to-concrete-5
Introduction to-concrete-5Introduction to-concrete-5
Introduction to-concrete-5
Ketan Raval
 
Atomic design
Atomic designAtomic design
Atomic design
Brad Frost
 
Highly Maintainable, Efficient, and Optimized CSS
Highly Maintainable, Efficient, and Optimized CSSHighly Maintainable, Efficient, and Optimized CSS
Highly Maintainable, Efficient, and Optimized CSS
Zoe Gillenwater
 
Joomla Beginner Template Presentation
Joomla Beginner Template PresentationJoomla Beginner Template Presentation
Joomla Beginner Template Presentation
alledia
 
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
Codecamp Romania
 
Responsive web design
Responsive web designResponsive web design
Responsive web design
AirticsTrainer
 
6 Special Howtos for Drupal
6 Special Howtos for Drupal6 Special Howtos for Drupal
6 Special Howtos for Drupal
Wingston
 
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
 
18. images in symfony 4
18. images in symfony 418. images in symfony 4
18. images in symfony 4
Razvan Raducanu, PhD
 
Magento mega menu extension
Magento mega menu extensionMagento mega menu extension
Magento mega menu extension
Bun 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 Usability
Teamstudio
 
Maintainable Frontend Development with BEM
Maintainable Frontend Development with BEMMaintainable Frontend Development with BEM
Maintainable Frontend Development with BEM
Varya Stepanova
 
Introduction to BOOTSTRAP
Introduction to BOOTSTRAPIntroduction to BOOTSTRAP
Introduction to BOOTSTRAP
Jeanie 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 Carey
jdaychi
 

Similaire à 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
 

Plus de Plasterdog Web Design

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

Plus de 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
 

Dernier

Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
SitimaJohn
 
Recommendation System using RAG Architecture
Recommendation System using RAG ArchitectureRecommendation System using RAG Architecture
Recommendation System using RAG Architecture
fredae14
 
OpenID AuthZEN Interop Read Out - Authorization
OpenID AuthZEN Interop Read Out - AuthorizationOpenID AuthZEN Interop Read Out - Authorization
OpenID AuthZEN Interop Read Out - Authorization
David Brossard
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
Brandon Minnick, MBA
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
MichaelKnudsen27
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
Jakub Marek
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
DanBrown980551
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
Tatiana Kojar
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Tosin Akinosho
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
Chart Kalyan
 
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying AheadDigital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Wask
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
saastr
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
kumardaparthi1024
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
IndexBug
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
danishmna97
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
Edge AI and Vision Alliance
 

Dernier (20)

Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
 
Recommendation System using RAG Architecture
Recommendation System using RAG ArchitectureRecommendation System using RAG Architecture
Recommendation System using RAG Architecture
 
OpenID AuthZEN Interop Read Out - Authorization
OpenID AuthZEN Interop Read Out - AuthorizationOpenID AuthZEN Interop Read Out - Authorization
OpenID AuthZEN Interop Read Out - Authorization
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
 
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying AheadDigital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying Ahead
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
 

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