-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathreadme.txt
More file actions
228 lines (173 loc) · 7.81 KB
/
readme.txt
File metadata and controls
228 lines (173 loc) · 7.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
=== Pattern CSS - The CSS Editor For Blocks ===
Contributors: kbat82
Tags: block, css, styles, inline, editor
Tested up to: 7.0
Stable tag: 1.5.6
License: GPL-2.0-or-later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Add a CSS editor to your blocks and patterns! Loads only where necessary. Supports adding global CSS too.
== Description ==
The missing inline block CSS editor for the Gutenberg editor. Very powerful with synced patterns as well. And it pairs well with global styles.
This plugin is perfect for users looking to add CSS for blocks without needing to create a child theme, or use a bloated plugin. Client safe too. CSS won't leak outside of the block, and only valid block CSS is persisted.
Star it on [GitHub](https://github.com/KevinBatdorf/pattern-css)
Follow me on Twitter [@kevinbatdorf](https://twitter.com/kevinbatdorf)
= How to =
- Every block will have a new "Pattern CSS" settings panel
- Open it and add any CSS. It will be scoped to the block
- To target the block directly, you must use the `[block]` selector
- To target any element *inside* the block, use the normal CSS selector
- Use `!important` to override your theme styles (use sparingly)
= Global Editor =
- Access global styles under the options menu (three dots) in the top right corner of the editor
- Additionaly, you can open from the Pattern CSS block editor controls
= Features =
- Powered by WebAssembly for fast and secure CSS parsing
- Smart loading. Only loads the CSS when the block is present
- Styles persist when changing themes
- Scopes styles to the block so that parent/sibling blocks are not affected
- It's fast
- CSS is minified and optimized
- It's safe. Invalid, non-spec CSS is never persisted
- Supports reusable (synced or not-synced) patterns
- See changes on the page as you make them
- Combines adjacent rules (to decrease size)
- Minifies colors and math functions to simplify according to spec
- Supports CSS nesting
= Basic Example =
`/* Target the block directly */
[block] {
background: antiquewhite;
padding: 2rem;
}
/* Target any inner elements */
a {
text-decoration-color: burlywood;
text-decoration-thickness: 2px;
text-decoration-style: solid !important;
}
a:hover {
text-decoration-color: darkgoldenrod;
}
/* Output: */
.pcss-a1b7b016{background:#faebd7;padding:2rem}.pcss-a1b7b016 a{text-decoration-color:#deb887;text-decoration-thickness:2px;text-decoration-style:solid!important}.pcss-a1b7b016 a:hover{text-decoration-color:#b8860b}`
= Supports Media Queries =
`@media (prefers-color-scheme: dark) {
[block] {
border-color: blue;
}
}
/* Output: */
@media (prefers-color-scheme:dark){.pcss-cddaa023{border-color:#00f}}`
= Combines Rules =
`[block] {
color: red;
}
.bar {
color: red;
}
/* Output: */
.pcss-3aa0f0fc,.pcss-3aa0f0fc .bar{color:red}`
= Fixes redundant properties =
`[block] {
padding-top: 5px;
padding-left: 50px;
padding-bottom: 15px;
padding-right: 5px;
}
/* Output: */
.pcss-3aa0f0fc{padding:5px 5px 15px 50px}`
= Supports CSS nesting =
`[block] {
padding: 1rem;
a {
color: red;
}
background: white;
/* Including media queries */
@media (prefers-color-scheme: dark) {
background: black;
color:white;
}
}
/* Output: */
.pcss-f526bb2d{background:#fff;padding:1rem;& a{color:red}@media (prefers-color-scheme:dark){&{color:#fff;background:#000}}}`
Check browser support for [CSS nesting](https://caniuse.com/css-nesting)
== Installation ==
1. Activate the plugin through the 'Plugins' screen in WordPress
== Frequently Asked Questions ==
= Error about application/wasm mime type =
Your server needs to be able to identify the mime type being used. See here: https://wordpress.org/support/topic/webassembly-instantiatestreaming-failed-because-your-server-does-not-serve-wasm/
= Can I use something other than [block]? =
You can add a custom selector via a PHP constant. It requires setting a type (type, attribute, etc) and the name.
Here's an example for "foo { color: red }", where foo will be replaced with .pcss-h3Hso39bsK (or something similar):
Add this to functions.php:
`define('PATTERN_CSS_SELECTOR_OVERRIDE', ['name' => 'foo', 'type' => 'type']);`
= Can I manually set the class ID? =
By default, class IDs are auto-generated. If you need to manually set or change a block's class ID (e.g. to match an existing class), you can enable this by adding the following constant to wp-config.php or functions.php:
`define('PATTERN_CSS_ALLOW_MANUAL_OVERRIDE', true);`
Once enabled, the ID field in the Advanced panel becomes editable. Type your desired class name and press "Apply" to save it. The value will be slugified automatically.
== Screenshots ==
1. Add styles not available in the editor (supoprts nesting)
2. Add animation using the global editor
3. Will warn you if your CSS is invalid
4. Works with reusable and synced patterns
== Changelog ==
= 1.5.6 - 2026-04-11 =
- Removes class ID from block when CSS is cleared
= 1.5.5 - 2026-03-24 =
- Added manual class ID override (opt-in via constant)
- Warns when duplicate class IDs are detected in the editor
- Prevents duplicate inline styles on the frontend
- Switched to Biome for linting and formatting
- Switched to Playwright and WP Playground for testing
= 1.5.4 - 2026-03-23 =
- Fixed dynamic blocks with POST
= 1.5.3 - 2025-09-27 =
- Fixes an issue where filtered attributes sent wp/v2/block-renderer causes a block validation error
= 1.5.2 - 2025-05-21 =
- Fixes an overflow bug in the editor
= 1.5.1 - 2025-05-18 =
- Retagging for release
= 1.5.0 - 2025-05-18 =
- Adds support for global styles via a new editor
= 1.4.0 - 2025-05-12 =
- Adds a draggable, resizable popout mode
- Updates CSS engine to include recent CSS features
- Allows "supports" support scoped to the block
= 1.3.0 - 2025-01-27 =
- Switches to useStyleOverride for injecting styles
= 1.2.6 - 2024-09-20 =
- Removes an unecessary html escape that mangled some css.
= 1.2.5 - 2024-07-28 =
- Fixed a small bug where a block may not have attributes when we access them.
= 1.2.4 - 2024-07-21 =
- Renamed the panel to Pattern CSS to differenciate it from the core panel on FSE
= 1.2.3 - 2024-05-09 =
- Removed globals like @import, @font-face, and @keyframes (and others)
= 1.2.2 - 2024-04-19 =
- Fixed an issue where CSS media queries using <= were stripped out
- Removed loading the viewer for users without the edit_css cap
- Removed the tag stripping output - now only privlidged users can use
- Updated tests to run on modern WP (by disabling the iframe)
= 1.2.1 - 2024-02-22 =
- Removed the example code and added a useful default
- Render blocks now work - now adds the id to the main class list
= 1.2.0 - 2024-02-20 =
- Feature: Adds support for CSS nesting
- Removes the code example on focus and adds it back on blur (if empty)
- Lets users define an additional block selector
- Adds a notice that the site logo isn't currently supported
= 1.1.0 - 2024-02-18 =
- Prevent adding classes to blocks unless CSS is added
- Force the settings area to the bottom (mainly for custom blocks)
= 1.0.1 - 2023-11-04 =
- Fixed a bug where the it would crash on the pattern manager page
= 1.0.0 - 2023-07-15 =
- Feature: Now supports reusable blocks/patterns
- Update: Removed the "per page" functionality to limit the scope of this plugin to blocks and reusable patterns only
- Performance: Added global loading strategy to prevent per block n+1 loading issues
- Improvement: Added the option to update the CSS selector used for scoping (useful for duplicating blocks)
- Improvement: Added some examples when no CSS is present
- Improvement: Removed the public className attribute requirement from the Additional Settings area
- Improvement: Instead of saving as meta on a post, it now pulls from the attribute directly during page load (via the pre_render_block filter).
- Fix: Now it will only show on post types with the public setting set to true