Unlock Hidden Power: 6 Little-Known Ways to Master Custom Block Styles in WordPress
The code referenced in this post is also available on GitHub:
You’ll want to have a basic understanding of CSS to follow along. Being comfortable with theme.json
is also key, and knowing a bit about PHP and WordPress hooks will definitely come in handy.
To follow along or use the example code, you can use Studio, our free and open source local development environment, available for Mac and Windows.
- What are custom block styles?
- Method 1: add a block style via a JSON file (/styles folder)
- Method 2: register block style in PHP and style it via theme.json
- Method 3: add a block style with register_block_style() (PHP)
- Method 4: register block styles using JavaScript + CSS
- Optional: removing unwanted core block styles
- Summary: custom block styles at a glance
- Resources to learn more
What are custom block styles?
Custom block styles let you define alternative visual treatments for existing blocks, like adding a border, changing the background, or tweaking typography.