Skip to content
JS Filters

lzb.editor.PreviewServerCallback.replaceNode

Filter called for every node while the editor preview parses the rendered block markup. Return a React element to put in place of the node, or the default null to leave the node to the standard handling.

Use it to give a custom component of your own the same treatment <InnerBlocks /> gets: written as a tag in the block code, turned into a real editor component in the preview.

Attributes

NameTypeDescription
customNodeJSX | nullreplacement node, null by default
domNodeObjectparsed node, with name, attribs and children
dataObjectprops, parserOptions, domToReact, prepareAttributes

prepareAttributes converts the raw markup attributes the way the rest of the parser does: "true" and "false" become booleans, class becomes className.

Usage

JS
wp.hooks.addFilter(
  "lzb.editor.PreviewServerCallback.replaceNode",
  "my.custom.namespace",
  function (customNode, domNode, data) {
    if (domNode.name !== "myComponent") {
      return customNode;
    }
 
    const atts = data.prepareAttributes(domNode.attribs);
 
    return <div className={atts.className}>{atts.label}</div>;
  }
);

Returning anything other than null stops the default handling for that node, so return the incoming customNode untouched for every node you do not care about.

Was this article helpful?

Copyright © 2026 Lazy Blocks.