Sliders & carousels

Before-After Slider for WordPress - No Plugin Needed

Stefan Pakic3 min read

A before-after image slider with a draggable handle comparing two photos

Most WordPress before-after slider plugins are bloated - they load extra CSS, JavaScript, and sometimes even jQuery just for one UI component. You can skip all of that. One lightweight script tag and a Custom HTML block is all you need.

The slider above is a live demo. That exact component will be on your WordPress site in about two minutes.

Step 1: Add the script tag

You need to load the OneType Transforms script on your site once. The easiest way is with the free WPCode plugin (2M+ installs):

  1. Go to Plugins > Add New
  2. Search for WPCode
  3. Click Install Now, then Activate
  4. Go to Code Snippets > Header & Footer
  5. Paste this in the Header section:
<script src="https://cdn.transforms.onetype.ai/script/57095981335841558d328d599e6f5322.js"></script>
  1. Click Save Changes

Done. The script now loads on every page of your WordPress site. No account needed - the before-after slider is free.

Step 2: Add the slider to a page

Gutenberg (Block Editor)

  1. Edit the page where you want the slider
  2. Click the + button to add a new block
  3. Search for Custom HTML and select it
  4. Paste this:
<div ot="before-after">
  <img src="YOUR_BEFORE_IMAGE_URL" alt="Before">
  <img src="YOUR_AFTER_IMAGE_URL" alt="After">
</div>
  1. Replace the image URLs with your actual images (upload them in Media Library first and copy the URLs)
  2. Save or publish the page

Classic Editor

  1. Click the Text tab (top right of the editor, next to Visual)
  2. Paste the same HTML code
  3. Save or publish

WordPress.com users

If you are on WordPress.com (not self-hosted), it depends on your plan:

  • Business or Commerce plan - works exactly like self-hosted. Install WPCode, add the script tag, use Custom HTML blocks.
  • Free, Personal, or Premium plans - you cannot install plugins. Instead, add both the script tag and the slider HTML together in a single Custom HTML block on each page.

For lower WordPress.com plans, paste this in a Custom HTML block:

<script src="https://cdn.transforms.onetype.ai/script/57095981335841558d328d599e6f5322.js"></script>

<div ot="before-after">
  <img src="before.jpg" alt="Before">
  <img src="after.jpg" alt="After">
</div>

Customization

All options are HTML attributes on the same div:

  • ot-direction="vertical" - slide top to bottom
  • ot-label-before="Original" - label on the before side
  • ot-label-after="Edited" - label on the after side
  • ot-position="30" - start at 30% instead of 50%
  • ot-hover="true" - follow mouse instead of drag

Why not just use a plugin?

You can, but most before-after slider plugins add a lot of overhead. They load their own CSS frameworks, JavaScript libraries, admin panels, and settings pages. Some still depend on jQuery.

With OneType Transforms, you get a single lightweight script that only loads what you use. No admin panel, no settings page, no database entries. Just HTML attributes.

And the before-after slider is completely free. Check out the main before-after slider guide for all customization options, or browse more transforms at transforms.onetype.ai.

More posts

All

Build it today. Pay when it goes live.

Every feature is unmetered while you build.

Start building