Skip to content

diffyweb/wp-balance-text

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

wp-balance-text

A tiny WordPress plugin that adds a Balance toggle to the native Typography panel on every block. Applies CSS text-wrap: balance via a single className.

What it does

Two ways to apply CSS text-wrap: balance to your content:

  1. Per-block toggle. Slots a one-click control into the editor's native Typography panel — same panel that holds Size, Font, Drop cap, Fit text, etc. Click + in the panel header → enable Balance on the selected block.
  2. Site-wide defaults. Settings → Balance Text: pick block types that should be balanced by default. Out of the box, headings H1–H6 are on (matching the common convention). Optional: Paragraph, Quote, Pullquote, Verse. A "Settings" link also appears next to Activate/Deactivate on the Plugins screen.

Result: headlines and short paragraphs stop stranding a single word on the last line. Per-block toggles compose cleanly with the site-wide defaults — they're additive opt-in, not overrides.

How it works

  • One editor.BlockEdit filter, fires for every block type. No per-block-type registration.
  • Storage is a text-balance token pushed onto the block's existing className attribute. No custom attributes, no migrations, no lock-in.
  • CSS is enqueued via wp_enqueue_block_assets so the editor preview matches the front-end.
  • Composes with any is-style-* block style variation already applied.

Files

wp-balance-text.php   # plugin header, enqueues, Settings API, dynamic <style> emitter
assets/editor.js      # the Typography-panel toggle (one editor.BlockEdit filter)
assets/style.css      # .text-balance + .balance-text utility classes

That's the whole plugin.

Installation

  1. Clone or download into /wp-content/plugins/wp-balance-text/.
  2. Activate via the Plugins screen (or wp plugin activate wp-balance-text).
  3. Open any block in the editor → Typography panel → click the + menu → enable Balance.

Requirements

  • WordPress 6.4+ (for the stable ToolsPanelItem slot; gracefully falls back to the experimental version on older builds).
  • PHP 7.4+.
  • Modern browser for the text-wrap: balance rule itself (Chrome 114+, Edge 114+, Firefox 121+, Safari 17.5+). Older browsers ignore the rule and fall back to default wrapping — no breakage.

License

GPL-2.0-or-later. See LICENSE.

About

WordPress plugin: adds a Balance toggle to the native Typography panel on every block. Applies CSS text-wrap: balance via a single className. One editor.BlockEdit filter, composes with any block style variation.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors