WesleySmits/agent-skills / .agent/skills/wordpress-fse-generator
generating-wordpress-fse-blocks
VerifiedGenerates WordPress Full Site Editing blocks and theme files. Use when the user asks about block.json, Gutenberg blocks, FSE themes, WordPress block development, or theme.json configuration.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 3.8 KB |
| examples/block-templates.md | markdown | 6.9 KB |
| examples/functions-php.md | markdown | 7.0 KB |
| examples/theme-json.md | markdown | 3.8 KB |
examples/block-templates.md
View on GitHub# Block Templates
## block.json (Block Metadata)
```json
{
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 3,
"name": "theme-name/my-block",
"version": "1.0.0",
"title": "My Block",
"category": "theme",
"icon": "smiley",
"description": "A custom block for displaying content.",
"keywords": ["custom", "content"],
"textdomain": "theme-name",
"attributes": {
"title": {
"type": "string",
"default": ""
},
"content": {
"type": "string",
"default": ""
},
"mediaId": {
"type": "number"
},
"mediaUrl": {
"type": "string"
},
"alignment": {
"type": "string",
"default": "none"
}
},
"supports": {
"html": false,
"align": ["wide", "full"],
"color": {
"background": true,
"text": true,
"link": true
},
"spacing": {
"margin": true,
"padding": true
},
"typography": {
"fontSize": true,
"lineHeight": true
}
},
"editorScript": "file:./index.js",
"editorStyle": "file:./index.css",
"style": "file:./style-index.css",
"render": "file:./render.php"
}
```
## Edit Component (Editor View)
```tsx
// src/blocks/my-block/edit.tsx
import { __ } from "@wordpress/i18n";
import {
useBlockProps,
RichText,
MediaUpload,
MediaUploadCheck,
InspectorControls,
BlockControls,
AlignmentToolbar,
} from "@wordpress/block-editor";
import {
PanelBody,
Button,
TextControl,
ToggleControl,
} from "@wordpress/components";
import type { BlockEditProps } from "@wordpress/blocks";
interface Attributes {
title: string;
content: string;
mediaId?: number;
mediaUrl?: string;
alignment: string;
}
export default function Edit({
attributes,
setAttributes,
}: BlockEditProps<Attributes>) {
const { title, content, mediaId, mediaUrl, alignment } = attributes;
const blockProps = useBlockProps({
className: `align-${alignment}`,
});
const onSelectMedia = (media: { id: number; url: string }) => {
setAttributes({
mediaId: media.id,
mediaUrl: media.url,
});
};
const removeMedia = () => {
setAttributes({
mediaId: undefined,
mediaUrl: undefined,
});
};
return (
<>
<BlockControls>
<AlignmentToolbar
value={alignment}
onChange={(newAlign) =>
setAttributes({ alignment: newAlign || "none" })
}
/>
</BlockControls>
<InspectorControls>
<PanelBody title={__("Block Settings", "theme-name")}>
<MediaUploadCheck>
<MediaUpload
onSelect={onSelectMedia}
allowedTypes={["image"]}
value={mediaId}
render={({ open }) => (
<div>
{!mediaUrl && (
<Button onClick={open} variant="secondary">
{__("Select Image", "theme-name")}
</Button>
)}
{mediaUrl && (
<>
<img src={mediaUrl} alt="" style={{ maxWidth: "100%" }} />
<Button
onClick={removeMedia}
variant="link"
isDestructive
>
{__("Remove Image", "theme-name")}
</Button>
</>
)}
</div>
)}
/>
</MediaUploadCheck>
</PanelBody>
</InspectorControls>
<div {...blockProps}>
<RichText
tagName="h2"
value={title}
onChange={(value) => setAttributes({ title: value })}
placeholder={__("Enter title...", "theme-name")}
/>
{mediaUrl && <img src={mediaUrl} alt="" />}
<RichText
tagName="p"
value={content}
onChange={(value) => setAttributes({ content: value })}
placeholder={__("Enter content...", "theme-name")}
/>
</div>
</>
);
}
```
## Save Component (Frontend Output)
**Static save (stored in post content):**
```tsx
// src/blocks/my-block/save.tsx
import { useBlockProps, RichText } from "@wordpress/block-editor";
interface Attributes {
title: string;
content: string;
mediaUrl?: string;
alignment: string;
}
export default function Save({ attributes }: { attributes: Attributes }) {
const { title, content, mediaUrl, alignment } = attributes;
const blockProps = useBlockProps.save({
className: `align-${alignment}`,
});
return (
<div {...blockProps}>
<RichText.Content tagName="h2" value={title} />
{mediaUrl && <img src={mediaUrl} alt="" />}
<RichText.Content tagName="p" value={content} />
</div>
);
}
```
## Dynamic Render (PHP)
```php
<?php
// src/blocks/my-block/render.php
/**
* @var array $attributes Block attributes.
* @var string $content Block default content.
* @var WP_Block $block Block instance.
*/
$title = $attributes['title'] ?? '';
$content = $attributes['content'] ?? '';
$media_url = $attributes['mediaUrl'] ?? '';
$alignment = $attributes['alignment'] ?? 'none';
$wrapper_attributes = get_block_wrapper_attributes([
'class' => 'align-' . esc_attr($alignment),
]);
?>
<div <?php echo $wrapper_attributes; ?>>
<?php if ($title) : ?>
<h2><?php echo wp_kses_post($title); ?></h2>
<?php endif; ?>
<?php if ($media_url) : ?>
<img src="<?php echo esc_url($media_url); ?>" alt="" />
<?php endif; ?>
<?php if ($content) : ?>
<p><?php echo wp_kses_post($content); ?></p>
<?php endif; ?>
</div>
```
## Block Registration
```ts
// src/blocks/my-block/index.ts
import { registerBlockType } from "@wordpress/blocks";
import Edit from "./edit";
import Save from "./save";
import metadata from "./block.json";
import "./style.scss";
import "./editor.scss";
registerBlockType(metadata.name, {
edit: Edit,
save: Save,
});
```
```ts
// src/blocks/index.ts
import "./my-block";
import "./another-block";
// Register all blocks
```
## PHP Registration (Dynamic Blocks)
```php
// inc/blocks.php
<?php
function theme_name_register_blocks(): void {
$blocks = [
'my-block',
'another-block',
];
foreach ($blocks as $block) {
register_block_type(__DIR__ . '/../build/blocks/' . $block);
}
}
add_action('init', 'theme_name_register_blocks');
```
## Block Styles
```scss
// src/blocks/my-block/style.scss (frontend + editor)
.wp-block-theme-name-my-block {
padding: var(--wp--preset--spacing--40);
border-radius: var(--wp--preset--spacing--10);
h2 {
font-size: var(--wp--preset--font-size--large);
margin-bottom: var(--wp--preset--spacing--20);
}
img {
width: 100%;
height: auto;
border-radius: var(--wp--preset--spacing--10);
}
}
// src/blocks/my-block/editor.scss (editor only)
.wp-block-theme-name-my-block {
border: 1px dashed #ccc;
&.is-selected {
border-color: var(--wp-admin-theme-color);
}
}
```
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack." | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |