A lightweight WordPress plugin for responsive before/after image comparison sliders with a draggable arrow handle. Works out of the box with KadenceWP (and any other block theme).
Ships two ways to embed a slider:
- Gutenberg block — media-library pickers, live editor preview, block sidebar controls
[before_after]shortcode — for classic editor, widgets, or page builders
- Horizontal or vertical orientation (per instance)
- Optional "Before" / "After" corner labels
- Per-image alt text for accessibility
- Adjustable starting handle position (0–100%)
- Touch, mouse, and keyboard controls (arrow keys when focused)
- Fully responsive — scales to any container
- Multiple sliders per page, no collisions
- Assets only enqueue on pages that render a slider
- Themeable via CSS custom properties (
--wpba-handle-color,--wpba-label-bg, etc.)
Slider UI is powered by the MIT-licensed img-comparison-slider web component, vendored locally — no CDN dependency.
- Download the plugin zip from the releases page.
- In WordPress: Plugins → Add New → Upload Plugin, pick the zip, activate.
git clone https://github.com/evankrob/wordpress-before-after.git
cd wordpress-before-after
npm install
npm run buildThen symlink or copy the folder into wp-content/plugins/ and activate.
Insert Before / After Slider from the block inserter (under Media). In the sidebar, pick a Before image and an After image, set optional labels, orientation, and starting position.
[before_after before="123" after="456"]
Full attributes:
| Attribute | Type | Default | Description |
|---|---|---|---|
before |
int | — | Attachment ID (preferred — gives responsive srcset + alt) |
after |
int | — | Attachment ID |
before_url |
url | — | Fallback URL if no attachment ID |
after_url |
url | — | Fallback URL |
before_label |
string | "" |
Optional corner label text |
after_label |
string | "" |
Optional corner label text |
before_alt |
string | attachment alt | Alt-text override |
after_alt |
string | attachment alt | Alt-text override |
orientation |
string | horizontal |
horizontal or vertical |
start |
int | 50 |
Starting handle position, 0–100 |
Override the CSS custom properties on .wpba-slider-wrap (or globally):
.wpba-slider-wrap {
--wpba-handle-color: #ff5a00;
--wpba-divider-width: 3px;
--wpba-label-bg: rgba(20, 20, 20, 0.8);
--wpba-label-color: #fff;
}wordpress-before-after.php Plugin header + bootstrap
includes/
class-plugin.php Block registration, asset loading, shared renderer
class-shortcode.php [before_after] handler
render-slider.php Shared HTML template (block + shortcode)
src/block/ Block source — compiled by @wordpress/scripts
build/block/ Compiled block output (committed so zip installs work)
assets/
img-comparison-slider.js Vendored web component (v8.0.6, MIT)
frontend.css Frontend styles
npm run start # watch mode for src/block
npm run build # production build- WordPress 6.4+
- PHP 7.4+
Issues and PRs welcome. For larger changes, please open an issue first to discuss.
GPL-2.0-or-later — matches WordPress core.
Slider web component: img-comparison-slider (MIT).
Developed by RaleighDigital.com.