plugin-icon

BlockGlow — Per-block Custom CSS

제작자: Mary Rose Elbambo·
Adds a "Custom CSS" inspector panel to every Gutenberg block and saves per-block CSS files to uploads for front-end enqueuing.
버전
1.2.0
최근 업데이트일
May 11, 2026
BlockGlow — Per-block Custom CSS

BlockGlow adds a “BlockGlow — Custom CSS” panel to the inspector of every block. Use it to scope custom CSS to a single block instance. The plugin stores CSS in the uploads folder (under uploads/blockglow/) and enqueues the generated CSS file when rendering on the front end. If the uploads directory isn’t writable or file write fails, BlockGlow will fall back to outputting inline styles.

Key features:

  • Adds two block attributes to every block: blockglowCustomCSS and blockglowId.
  • Inspector panel with a CodeMirror-backed code editor (if WordPress provides it) or a fallback textarea supporting Tab and Shift+Tab outdent.
  • Live preview inside the block editor: custom CSS is scoped to the block in the editor so you can see the effect while editing.
  • CSS files are saved to wp-content/uploads/blockglow/blockglow-<id>.css and enqueued on the front end as a linked stylesheet; files are removed automatically when you clear the Custom CSS field.
  • Graceful fallback to inline styles when file writing isn’t possible.

How scoping works:

BlockGlow creates a unique blockglowId for each block instance and scopes your CSS with a wrapper selector like:

[data-blockglow-id="bg-xxxxxxx"] { /* your declarations */ }

For convenience you can use & as the wrapper shorthand in the editor. Example:

& .my-class { color: red; }

The plugin will replace & with the wrapper selector for both editor preview and front-end output.

Arbitrary section

Development notes:

  • Editor script: assets/js/blockglow-editor.js — registers attributes, provides the inspector panel and injects editor-scoped styles.
  • Main plugin file: blockglow.php — enqueues editor assets and filters render_block to attach per-block CSS files or inline styles.
  • Upload path: wp_upload_dir() + /blockglow/.
  • File writes/deletes: BlockGlow uses the WordPress Filesystem API (WP_Filesystem) when available for compatibility with hosts using FTP/SFTP; when unavailable it will attempt direct writes. Editing capability is required (edit_posts) or operations performed via REST save.
  • Per-post bundling: BlockGlow now generates a single stylesheet per post (blockglow-post-<ID>.css) on post save which contains the combined CSS from all blocks in that post. This reduces HTTP requests and improves performance.
  • Admin UI: A new submenu under Tools “BlockGlow CSS” lists generated files and allows administrators (capability is filterable) to delete them.
  • Capability: File generation/deletion is restricted by a filterable capability blockglow_manage_files_cap (default manage_options). You can change this capability via the filter if you want other roles to manage files.
  • If you’d like help preparing the plugin for WordPress.org (example readme.txt adjustments, SVN packaging, or adding screenshots), ping me and I can prepare the required assets and instructions.

Source Code

The plugin includes built/minified assets under assets/dist/ for distribution. The human-readable source for JavaScript is included in the plugin under assets/js/ (e.g. assets/js/blockglow-editor.js and assets/js/blockglow-admin.js). The plugin also contains a package.json and vite.config.js in the plugin root describing how to rebuild these assets locally using npm install and npm run build or npm run watch.

If you need the sources to be hosted externally, provide a URL and I will add it here (for example an upstream GitHub repository).

Installation Notes for WordPress.org

To publish on WordPress.org you will need:

  • A fully-formed readme.txt (this file) using the plugin directory readme format.
  • Screenshots (1.png, 2.png, etc.) placed in the assets/ directory when committing to SVN, or uploaded via the plugin admin UI after publishing.
  • A stable tag or commit to trunk/ in SVN. Typical workflow:
    1. Create a new plugin slug on https://wordpress.org/plugins/ and follow the email to get SVN access.
    2. Check out the plugin SVN repository, add your plugin files into trunk/, put screenshots into assets/, and tag a version.
    3. Commit and wait for the plugin page to become live.

Support

If you find issues or want improvements (for example: limiting who can edit per-block CSS, collecting styles into a single head include, or adding an admin UI to manage generated CSS files), open an issue in the repository or reply here and I will assist.

무료유료 요금제에서
설치하면 WordPress.com 서비스 약관서드파티 플러그인 약관에 동의하게 됩니다.
테스트된 버전
WordPress 6.8.5
이 플러그인은 다운로드할 수 있으며 에서 사용할 수 있습니다.