Introduction
I plan to rebuild my current theme into a full-site editing one and do so while live coding and live streaming.
Here’s the recap of the third streaming session.
Legend: šØš»āš» code, ā check, š read, š„ watch, š§ learn.
Part 1: php block pattern
- ā Wondered if it’s possible to create a dynamic php copyright inside my footer
- š https://developer.wordpress.org/block-editor/reference-guides/block-api/block-patterns/
- š§ Template and template parts are usually written in HTML, while block patterns are usually written in php. (cf twenty twenty two)
- š§ Patterns can be declared with the
register_block_pattern
function or with meta comments - šØš»āš» Created the patterns folder
- šØš»āš» Created a copyright.php file with a php dynamic date. Declared it using meta comments instead of a function.
- ā How do you load a block pattern from a template file ?
- š§ Like this :
<!-- wp:pattern {"slug":"myblocktheme/footer-copyright"} /-->
- šØš»āš» Included the pattern.
- ā The footer is now dynamic
Part 2: Navigation block
- ā In the last session, we were thinking about the navigation block possibilities. Was it possible to create a dynamic menu?
- š§ It turns out I accidentally used a
wp:page-list
block, which is dynamic. It pulls all the created pages. So that’s the dynamic option. - š§ The page-list block can be converted to a series of
wp:navigation-link
blocks, which is now what I’m using. It’s the manual option.
- š§ It turns out I accidentally used a
Part 3: Theme.json
- šØš»āš» There were no theme.json file in my theme, declared a minimum one with the version and the scheme.
- š https://developer.wordpress.org/block-editor/how-to-guides/themes/theme-json/
- Colors
- šØš»āš» Added a settings / color / palette section, with 4 colors in them.
- ā They were available in global styles
- š§ WordPress creates automatic CSS variables for certain elements declared in theme.json
- šØš»āš» Added a styles / color / background section, referencing the
var(--wp--preset--color--light)
variable. - šØš»āš» Added a styles / color / text section, referencing the
var(--wp--preset--color--dark)
variable. - ā My website now has the right background color and the right text color
- Fonts
- š„ https://wordpress.tv/2022/09/15/block-theme-builders-choosing-using-fonts/
- šØš»āš» Added a typography / fontFamilies section.
- šØš»āš» Declared the “itc-avant-garde-gothic-pro”, Arial, sans-serif font family
- ā My website is now displayed with an Arial font.
- ā How do you include a distant font ?
- šØš»āš» Tried to declare a font face with a source url.
- š§ If you are using theme.json and trying to reference an external source it will not work. Theme.json only recognizes local URLs. You would have to wp_enqueue the font elsewhere in order to use an external host.
Plan for next time
- šØš»āš» Work on the home page
Link to the stream video
If you found this article interesting, I encourage you to follow my work via the form below. I mainly write about production teams' optimization, processes, management, and the tooling around those subjects. Iām even preparing an online course to concentrate all of this for you in a unique place. I hope it can help you get the very best out of your development team.
Follow my work
Follow me to get notified of new posts, resources, and online courses I create.