Different markup on the frontend and in the editor
To render and element based on the block context (frontend or editor), use the data-display
attribute.
Supported values are:
frontend
: Only render this element on the frontendeditor
: Only render this element in the editorselected
: Only render this element in the editor when the block is selectednot-selected
: Only render this element in the editor when the block is not selected
- block.html
- edit.js
- render.php
- block.json
- index.js
block.html
<section>
<div>Visible everywhere</div>
<div data-display="frontend">Visible on the frontend only</div>
<div data-display="editor">Visible in the editor only</div>
<div data-display="selected">
Visible in the editor when the block is selected only
</div>
<div data-display="not-selected">
Visible in the editor when the block is not selected only
</div>
</section>