Skip to main content

Text Expander

Show a short excerpt with a Read more toggle that reveals the rest — for long copy, FAQs, disclosures and specification lists. Core has no equivalent block.

The block renders through the text_expander element — the same PHP that runs in the page builder, so the front end is identical either way.

What the sidebar exposes

OptionWhat it does
visible_contentThe excerpt shown before expanding — edits markup, see below
hidden_contentThe rest, revealed on toggle — edits markup, see below
btn_showLabel for the expand button
btn_hideLabel for the collapse button
toggle_iconIcon shown on the toggle
show_btn_positionWhere the expand button sits
hide_btn_positionWhere the collapse button sits
count_modeHow the truncation length is measured
show_ellipsisPrint an ellipsis at the cut
merge_boundaryJoin the two halves cleanly mid-sentence
click_anywhereLet a click anywhere in the block toggle it
initially_openStart expanded
visible_colorExcerpt text colour
hidden_colorRevealed text colour
btn_colorToggle button colour

Anything not listed stays available in the page builder, and round-trips untouched — the block only writes the values you change.

The preview shows both halves, expanded

The collapse is applied by the element's front-end script, which the block deliberately does not replay. So the canvas shows the excerpt and the hidden content, with both button labels — not the collapsed state a visitor first sees.

That is the better preview while editing: you are writing both halves and want to see both. Replaying the runtime would hide the text you just typed, and a click meant to select the block would silently expand it instead. Visitors get the real toggle.

Both content fields edit markup, not rich text

visible_content and hidden_content are wp-editor options, so in a block sidebar they edit HTML directly rather than showing a WYSIWYG — the reasoning is on that option type's page.

note
native_details is page-builder only

The element can render as a native <details> / <summary> pair instead. That swaps the markup, the styling hooks and the keyboard behaviour all at once — a structural choice worth making in the page builder where the result sits next to everything else, rather than a switch to flip in a narrow sidebar.