Home › WordPress › WordPress block theme & blocks rules

WordPress block theme & blocks rules

Cursor rules for WordPress block themes and custom blocks: theme.json v3, block.json, patterns, and @wordpress/scripts.

CursorWordPress

How to use

Save this as .cursor/rules/wp-blocks.mdc in your repository root, commit it, and your agent will pick it up automatically. Edit the commands to match your project.

Note: Review and test before use. Provided as is, without warranty. See Terms.

.cursor/rules/wp-blocks.mdcDownload  
---
description: WordPress block theme & blocks conventions
globs: ["**/*.php","**/block.json","theme.json","src/**/*.js","src/**/*.jsx"]
alwaysApply: false
---

# WordPress block themes and custom blocks

## Block themes
- Global styles and settings live in `theme.json` (schema version 3): color palette, typography scale, spacing presets, layout widths. Use presets (`var(--wp--preset--color--primary)`) instead of hard-coded CSS.
- Templates in `templates/*.html` and parts in `parts/*.html` use block markup only. Register reusable layouts as patterns in `patterns/*.php` with the header comment (Title, Slug, Categories).
- Keep `style.css` for the theme header and minimal extras; most styling goes through `theme.json` and block style variations (`styles/*.json`).

## Custom blocks
- Scaffold with `npx @wordpress/create-block` and build with `@wordpress/scripts` (`npm run start` / `npm run build`).
- Metadata in `block.json` (`apiVersion: 3`, `attributes`, `supports`, `textdomain`); register with `register_block_type( __DIR__ . '/build/my-block' )`.
- Use `supports` (color, spacing, typography) instead of custom controls when possible.
- Editor UI with `useBlockProps`, `RichText`, `InspectorControls` and components from `@wordpress/components`.
- Prefer dynamic blocks (`render.php`) for content that depends on data; static `save` output must stay stable or add `deprecated` entries to avoid block validation errors.
- Escape in `render.php` (`esc_html`, `wp_kses_post`) and use `get_block_wrapper_attributes()`.
- Strings via `__()` from `@wordpress/i18n`.

## Done when
`npm run build` and `npm run lint:js` pass, and the block inserts, saves, and reloads without validation warnings.

More: all WordPress rules · all Cursor rules

Related rules

WordPress plugin CLAUDE.md

CLAUDE.md for WordPress plugin development: prefixes, hooks, nonces and capabilities, sanitizing, escaping, and wp-env.

Claude Code (CLAUDE.md)WordPress

Shopify Liquid theme rules

Cursor rules for Shopify Online Store 2.0 themes: sections and blocks, JSON templates, Liquid performance, Theme Check.

CursorShopify

Shopify app AGENTS.md

AGENTS.md for Shopify apps built with Shopify CLI and the React Router template: auth, GraphQL Admin API, and webhooks.

AGENTS.mdShopify

Astro content site rules

Cursor rules for Astro 5 sites with content collections, islands, and zero-JS-by-default pages.

CursorAstro

Chrome extension (Manifest V3) rules

Cursor rules for building Manifest V3 browser extensions with TypeScript and minimal permissions.

CursorChrome extensions

Cloudflare Agents SDK rules

Cursor rules for stateful AI agents on Cloudflare (agents package): Durable Object state, SQL, scheduling, and WebSockets.

CursorCloudflare Workers / Hono

Get new rules weekly

One email a week: fresh rule files, agent tips, and what's changing in Cursor, Claude Code and Copilot. Free, unsubscribe anytime.

Opens the Rulestack Newsletter on beehiiv in a new tab. Or subscribe directly on beehiiv.