Performance: Block registration
This affects page load speed and interaction responsiveness by controlling how blocks are added and rendered in the editor and frontend.
register_block_type('my-plugin/my-block', array('editor_script' => 'my-block-editor-script', 'render_callback' => 'my_block_render_callback')); function my_block_render_callback($attributes) { wp_enqueue_script('my-block-frontend-script'); wp_enqueue_style('my-block-style'); return '<div>Block content</div>'; }
register_block_type('my-plugin/my-block', array('editor_script' => 'my-block-editor-script')); wp_enqueue_script('my-block-frontend-script'); wp_enqueue_style('my-block-style');
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Register block with unconditional frontend assets | Minimal | 0 | High due to style recalculation | [X] Bad |
| Register block with conditional asset loading via render callback | Minimal | 0 | Low, only when block present | [OK] Good |
registerBlockType in WordPress block development?registerBlockTyperegisterBlockType.registerBlockType and it requires a unique block name and an object with edit and save functions.edit and save functions.registerBlockType('myplugin/simple', {
edit: () => {
return wp.element.createElement('p', null, 'Hello Editor');
},
save: () => {
return wp.element.createElement('p', null, 'Hello Saved');
}
});edit function controls what the editor shows while editing. The save function controls what HTML is saved and shown on the front end.save function returns a paragraph with text 'Hello Saved', so this is the content saved in the post and shown to visitors.registerBlockType('myplugin/test', {
edit() {
return <p>Edit Block</p>
},
save() {
return <p>Save Block</p>
}
});wp.element.createElement or have JSX compiled.edit.edit updates the array attribute. save joins the array into a comma-separated string inside a paragraph tag for saving as HTML.attributes to store an array, edit to update it, and save to join array into a string inside a <p> tag. [OK]Pass the test and this pattern moves unknown