Blocks
Blocks
Make Gutenberg blocks with their own fields, from a folder in your theme. No build step.
In this chapter
The basics 5
- How a block works A block is a folder in ugly-blocks/ inside your theme:
- Making a block Saving writes ugly-blocks/hero/block.json, and the first time also render.php, with the code of each field ready to change. A file that exists is never replaced.
- The render file Inside the render file, ugly_get() and ugly_show() give the values of that block.
- Fields for a block A group is attached to a block with the location Block is hero.
- Editing a block in the editor Blocks
Settings and extras 7
- The Blocks screen, tab by tab UglyFields → Blocks lists your blocks as cards, in the same way as the list of groups. New block makes one. Edit opens it.
- LooksPro Versions of one block that the editor picks from the block toolbar, for example Dark and Light. Each look adds a class to the block, is-style-dark, is-style-light, for your CSS.
- Blocks inside the blockPro The editor can put other blocks (a paragraph, an image, a button) inside this one. Turn on Allow blocks inside, then:
- Added by itself, next to another blockPro Put the block next to another one without anyone adding it. For example, a banner after the content of every post.
- Your own CSS and JavaScript Name them in the block.json. WordPress loads them only on the pages that use the block.
- block.json: what is supported One rule: the block.json has nothing that the Blocks screen cannot set. Whatever you write by hand and whatever you set on the screen is the same thing. A key the screen cannot set is not…
- Registering a block from your theme The plugin registers the blocks of ugly-blocks/ by itself. You can also do it with WordPress' own function, from functions.php:
Looking after blocks 5
- Turning a block off A block that is off is no longer registered, so the editor does not offer it and the site shows nothing in its place. Its folder and its fields stay as they are, and it comes back when you…
- Removing a block Removing a block is done in your theme, not here. A block is your code, and UglyFields never deletes code.
- When the template fails If the template of a block fails or is missing:
- Block fields that are also fields of the page The data of a block normally lives inside the block, in the page content. With Save its data in the page too on, the values are also saved as fields of the page, so you can read them…
- Examples ugly-blocks/cta/render.php:
No page matches. Try another word.
Where to go next
| You want to… | Read |
|---|---|
| See complete blocks, step by step | Tutorials |
| Do one task | How do I…? Blocks |
| Bind a heading to a field with no code | Block Bindings |
Did this article answer your question?
Thank you. It helps us make the documentation better. Need more help?