Block Editor Best Practices
For users, designers, and developers
https://iamdani.sh | danishshakeel54@gmail.com
Danish Shakeel
Senior Software Engineer @
2
“Gutenberg may be the most hated feature of WordPress”
3
4
“Gutenberg is trying to appeal to both ‘simple’ and ‘advanced’ users, and thus is doing neither one of them fairly well.”
5
6
Pain points during the project
7
Outline
8
Using Block Editor
9
Blocks
10
Patterns
11
Synced vs Unsynced Patterns
12
How would you create a section showing �business hours?
Demo
13
Templates and Template Parts
14
Patterns vs Templates
15
| Template Part | Synced Pattern (Reusable block) | Regular Pattern |
Type | Site structure | User content | User content |
Syncing Ability | Synced | Synced | Un-synced |
Examples | Header Footer Sidebar | Business hours Banner Call to action button | Gallery Hero section |
The idea of components
16
So, what can be used as a component?
17
Stylebook
18
Developing block themes
19
Custom blocks: theme or plugin?
20
Directory Structure
your-blocks-plugin
├── assets/ // non-php code
│ ├── block-extensions/ // extensions for core blocks
│ ├── block-variations/ // variations for core blocks
│ ├── blocks/ // your custom blocks javascript
│ ├── js/ // other scripts
│ ├── styles/ // css
│ └── lib/ // utilities
├── inc/ // usually php code
│ ├── classes/ // plugin-related functionality
│ ├── helpers/ // helper functions
│ └── traits/ // we use singleton trait
├── tests/
└── your-blocks-plugin.php
21
theme.json
22
Use Fluid Typography
23
Use Fluid Typography [cont’d…]
24
.text { font-size: clamp(min-value, pref-value, max-value); } |
"settings": { "typography": { "fluid": true, "fontSizes": [ { "name": "Medium", "slug": "medium", "size": "2.375rem", // preferred value "fluidSize": { "min": "1.875rem", // used below 768px "max": "2.375rem" // used above 1600px } } ] } } |
Use block.json
25
Extending Core Blocks vs Custom Blocks
26
Core Blocks | Custom Blocks |
Avoid recreating the wheel by making the most of existing features; saves time | Developers have more control over the final product. |
Streamlines the development process for faster production and delivery | Poses less risk for disruption from breaking changes in WordPress core. |
Can benefit from future enhancements to the WordPress core block | Developers typically have a lot of experience in developing new blocks. |
Adding Video Controls to Cover Video
Case Study
27
Use Internationalization (i18n)
28
Use WordPress Components
29
Never compromise on code quality
30
Structure your block code properly
31
Documentation is key (and the lock)
32
Improving Site Experience
33
Site = Editor + Frontend
34
Keeping Responsiveness in Mind
35
Keeping Responsiveness in Mind [cont’d…]
36
>=1280px
<1280px
Accessibility
37
Final Words
38
Questions?
39
Thank you!�See you on 23.01.2025
40