Experience the powerful AI writing right inside WordPress
Show stunning before-and-after transformations with image sliders.
Improve user engagement by showing estimated reading time.
Written by Mahmuda Akter Isha
Showcase Designs Using Before After Slider.
Use a Swiper plugin for an easy no-code setup, or add Swiper.js manually for more design and performance control. You can customize navigation arrows, pagination, autoplay, and responsive layouts. The plugin method is best for beginners, while custom code suits advanced WordPress users.
Adding a slider is an effective way to showcase images, products, portfolio projects, testimonials, blog posts, and promotional content without making a page unnecessarily long.
However, searching for a “Swiper Slider WordPress plugin” can be confusing. Swiper is primarily a JavaScript slider library—not one specific WordPress plugin. You can integrate it into WordPress through a Gutenberg block plugin, a page builder, or custom code.
In this guide, you will learn how to use Swiper Slider in WordPress through three practical methods:
You will also learn how to make the slider responsive, accessible, fast, and easier to troubleshoot.
To use Swiper Slider in WordPress without coding, install a Swiper-powered block plugin such as WP Swiper, add its carousel block to a page, insert your slide content, and configure navigation, pagination, autoplay, looping, and responsive settings.
Developers can instead add Swiper.js to a child theme or custom plugin, enqueue its CSS and JavaScript files, create the required HTML structure, and initialize the slider with custom JavaScript.
The best method depends on how much control you need and whether you are comfortable editing code.
Swiper is a free, open-source JavaScript library for creating touch-enabled sliders and carousels. It is designed for modern browsers and supports touch gestures, responsive breakpoints, navigation arrows, pagination, autoplay, keyboard control, looping, multiple-slide layouts, and several transition effects.
A basic Swiper slider contains three main elements:
Optional elements can be added for navigation arrows, pagination dots, thumbnails, or scrollbars.
Swiper is not restricted to image sliders. A slide can contain:
This flexibility makes Swiper useful for many types of WordPress websites.
Swiper provides more control than many basic WordPress slideshow tools.
Visitors can swipe between slides on smartphones and tablets. Desktop users can navigate with arrows, pagination dots, keyboard controls, or mouse dragging.
Swiper supports breakpoint-based settings. You can display one slide on mobile, two on tablets, and three or more on desktop screens.
You are not limited to uploading images. Depending on your implementation, each slide can contain WordPress blocks, text, buttons, videos, products, testimonials, or custom layouts.
You can add:
Swiper can be configured for:
Modern Swiper implementations do not require jQuery, making them suitable for modern WordPress development.
Choose your implementation method before building the slider.
Use the plugin method when you want to create and edit sliders visually.
Use custom code when you need a highly specific design, dynamic data, conditional asset loading, or advanced Swiper configuration.
The easiest no-code approach is to use a Gutenberg-compatible plugin.
For this tutorial, we will use WP Swiper. It adds a carousel block to the WordPress block editor and allows standard WordPress blocks to be placed inside each slide. Its available settings include navigation, pagination, autoplay, looping, responsive breakpoints, vertical sliders, spacing, background images, overlays, and custom navigation icons.
Important: Different Swiper-powered plugins have different interfaces. Do not assume that every plugin creates the same dashboard menu or shortcode.
Log in to your WordPress dashboard and follow these steps:
WP Swiper currently works through the block editor rather than requiring a separate “Add New Slider” dashboard screen.
[Screenshot suggestion: WP Swiper installation screen in WordPress]
Navigate to Pages or Posts, and then open the content where you want to display the slider.
You can either edit an existing page or create a new one.
Click the block inserter button and search for:
WP Swiper
Select the main carousel block from the search results.
After adding the carousel block, create the number of slides you need.
Each slide can contain regular WordPress blocks, including:
For a basic image slider:
For a content slider, combine an image with a heading, description, and call-to-action button.
[Screenshot suggestion: Adding an Image block inside a WP Swiper slide]
Select the main Swiper block instead of an individual slide. The block sidebar will display the slider-level controls.
Depending on the current plugin version, you may be able to configure:
For a standard content carousel, try these settings:
Always preview the result at different screen widths.
Navigation arrows help visitors move manually between slides.
Pagination shows how many slides are available and which slide is currently active.
Enable one or both of these options:
Use controls with enough contrast against the slide background. Avoid placing arrows where they cover important text or faces in an image.
Autoplay can work well for logos, promotions, and simple image presentations. However, it should not move so quickly that visitors cannot read the content.
A practical starting point is:
Avoid autoplay for slides containing long paragraphs, forms, or information visitors must carefully read.
Select an individual slide to edit its specific content or appearance.
Depending on the block version, you may be able to configure:
Use the same image ratio across all slides to prevent distracting height changes.
Before publishing:
After completing the checks, click Publish or Update.
WP Swiper is primarily a Gutenberg block plugin. You add the slider directly through the WordPress editor.
Some other WordPress slider plugins generate shortcodes, but shortcode formats are plugin-specific. A shortcode such as [swiper_slider id="123"] will not work unless an installed plugin explicitly registers that shortcode.
[swiper_slider id="123"]
Never paste a shortcode from an unrelated tutorial without checking the documentation for your chosen plugin.
The custom-code method gives you more control over the design, loading behavior, HTML structure, responsive settings, and slider functionality.
This method is suitable when you:
Before editing code: Create a site backup and use a staging environment. Add the code to a child theme or custom functionality plugin so a theme update does not erase your work.
Inside your child theme, create these files:
your-child-theme/ ├── functions.php └── assets/ ├── css/ │ └── custom-swiper.css └── js/ └── custom-swiper.js
You will use:
functions.php
custom-swiper.css
custom-swiper.js
WordPress recommends loading front-end scripts with wp_enqueue_script() through the wp_enqueue_scripts action rather than adding random <script> tags to theme templates. The function also allows WordPress to manage dependencies, versions, footer loading, and supported loading strategies.
wp_enqueue_script()
wp_enqueue_scripts
<script>
Add the following code to the child theme’s functions.php file:
<?php /** * Load Swiper and the custom slider files. */ function codecanel_enqueue_swiper_assets(): void { // Load the files only on singular posts and pages. if ( ! is_singular() ) { return; } wp_enqueue_style( 'swiper', 'https://cdn.jsdelivr.net/npm/swiper@14/swiper-bundle.min.css', array(), '14' ); wp_enqueue_style( 'codecanel-custom-swiper', get_stylesheet_directory_uri() . '/assets/css/custom-swiper.css', array( 'swiper' ), '1.0.0' ); wp_enqueue_script( 'swiper', 'https://cdn.jsdelivr.net/npm/swiper@14/swiper-bundle.min.js', array(), '14', array( 'in_footer' => true, 'strategy' => 'defer', ) ); wp_enqueue_script( 'codecanel-custom-swiper', get_stylesheet_directory_uri() . '/assets/js/custom-swiper.js', array( 'swiper' ), '1.0.0', array( 'in_footer' => true, 'strategy' => 'defer', ) ); } add_action( 'wp_enqueue_scripts', 'codecanel_enqueue_swiper_assets' );
This example loads the slider files on individual posts, pages, and other singular content.
For better performance, you can make the condition more specific:
if ( ! is_page( 'portfolio' ) ) { return; }
You can also replace the page slug with a page ID:
if ( ! is_page( 123 ) ) { return; }
For a production website, consider downloading and hosting the Swiper files inside your own theme or plugin instead of depending permanently on a third-party CDN.
Open the page where you want to display the slider and add a Custom HTML block.
Paste this structure:
<div class="swiper codecanel-swiper" aria-label="Featured projects"> <div class="swiper-wrapper"> <article class="swiper-slide"> <img src="https://example.com/wp-content/uploads/project-one.webp" alt="Completed website redesign project" width="1200" height="675" loading="eager" > <div class="swiper-slide-content"> <h3>Website Redesign</h3> <p>A modern website redesign focused on speed and usability.</p> <a href="/project-one/">View Project</a> </div> </article> <article class="swiper-slide"> <img src="https://example.com/wp-content/uploads/project-two.webp" alt="Mobile application interface project" width="1200" height="675" loading="lazy" > <div class="swiper-slide-content"> <h3>Mobile Application</h3> <p>A responsive product interface created for mobile users.</p> <a href="/project-two/">View Project</a> </div> </article> <article class="swiper-slide"> <img src="https://example.com/wp-content/uploads/project-three.webp" alt="Online store development project" width="1200" height="675" loading="lazy" > <div class="swiper-slide-content"> <h3>Online Store</h3> <p>An optimized ecommerce experience built for conversions.</p> <a href="/project-three/">View Project</a> </div> </article> <article class="swiper-slide"> <img src="https://example.com/wp-content/uploads/project-four.webp" alt="Business dashboard design project" width="1200" height="675" loading="lazy" > <div class="swiper-slide-content"> <h3>Business Dashboard</h3> <p>A clear analytics dashboard for monitoring business data.</p> <a href="/project-four/">View Project</a> </div> </article> </div> <div class="swiper-pagination"></div> <button class="swiper-button-prev" type="button" aria-label="View previous slide" ></button> <button class="swiper-button-next" type="button" aria-label="View next slide" ></button> </div>
Replace the sample image URLs, text, alt attributes, and links with your own content.
The .swiper, .swiper-wrapper, and .swiper-slide classes are essential parts of the standard Swiper structure. Navigation and pagination elements are optional.
.swiper
.swiper-wrapper
.swiper-slide
Open:
/assets/js/custom-swiper.js
Add this JavaScript:
document.addEventListener('DOMContentLoaded', () => { const prefersReducedMotion = window.matchMedia( '(prefers-reduced-motion: reduce)' ).matches; const sliders = document.querySelectorAll('.codecanel-swiper'); sliders.forEach((slider) => { const slideCount = slider.querySelectorAll('.swiper-slide').length; new Swiper(slider, { slidesPerView: 1, slidesPerGroup: 1, spaceBetween: 16, speed: prefersReducedMotion ? 0 : 500, loop: slideCount > 3, watchOverflow: true, autoplay: prefersReducedMotion ? false : { delay: 5000, disableOnInteraction: true, pauseOnMouseEnter: true, }, keyboard: { enabled: true, onlyInViewport: true, }, a11y: { enabled: true, prevSlideMessage: 'Previous slide', nextSlideMessage: 'Next slide', firstSlideMessage: 'This is the first slide', lastSlideMessage: 'This is the last slide', }, pagination: { el: slider.querySelector('.swiper-pagination'), clickable: true, }, navigation: { nextEl: slider.querySelector('.swiper-button-next'), prevEl: slider.querySelector('.swiper-button-prev'), }, breakpoints: { 640: { slidesPerView: 2, spaceBetween: 20, }, 1024: { slidesPerView: 3, spaceBetween: 24, }, }, }); });
This setup provides:
Swiper supports configuration objects for accessibility, autoplay, breakpoints, navigation, keyboard controls, looping, and other behaviors.
Using document.querySelectorAll() allows multiple Swiper sliders to work on the same page.
document.querySelectorAll()
The navigation and pagination selectors are also searched inside each slider container. This prevents the arrow from one slider from accidentally controlling another slider.
/assets/css/custom-swiper.css
Add:
.codecanel-swiper { --swiper-navigation-size: 22px; --swiper-pagination-bullet-size: 10px; position: relative; width: 100%; padding: 4px 4px 48px; overflow: hidden; } .codecanel-swiper .swiper-slide { box-sizing: border-box; height: auto; overflow: hidden; border: 1px solid #e5e7eb; border-radius: 14px; background: #ffffff; box-shadow: 0 8px 24px rgba(15, 23, 42, 0.08); } .codecanel-swiper .swiper-slide img { display: block; width: 100%; aspect-ratio: 16 / 9; object-fit: cover; } .codecanel-swiper .swiper-slide-content { padding: 22px; } .codecanel-swiper .swiper-slide-content h3 { margin: 0 0 10px; font-size: 1.25rem; line-height: 1.3; } .codecanel-swiper .swiper-slide-content p { margin: 0 0 18px; line-height: 1.65; } .codecanel-swiper .swiper-slide-content a { display: inline-flex; align-items: center; min-height: 44px; font-weight: 600; text-decoration: none; } .codecanel-swiper .swiper-button-prev, .codecanel-swiper .swiper-button-next { width: 44px; height: 44px; border: 0; border-radius: 50%; background: rgba(255, 255, 255, 0.95); box-shadow: 0 4px 14px rgba(15, 23, 42, 0.16); cursor: pointer; } .codecanel-swiper .swiper-button-prev:focus-visible, .codecanel-swiper .swiper-button-next:focus-visible, .codecanel-swiper .swiper-pagination-bullet:focus-visible, .codecanel-swiper a:focus-visible { outline: 3px solid currentColor; outline-offset: 3px; } .codecanel-swiper .swiper-button-disabled { opacity: 0.4; cursor: not-allowed; } @media (max-width: 639px) { .codecanel-swiper .swiper-button-prev, .codecanel-swiper .swiper-button-next { width: 40px; height: 40px; } } @media (prefers-reduced-motion: reduce) { .codecanel-swiper *, .codecanel-swiper *::before, .codecanel-swiper *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; } }
Customize the spacing, borders, shadows, typography, and button appearance to match your WordPress theme.
After adding the files:
You can also display a custom Swiper slider inside an Elementor page.
The safest method is to enqueue the Swiper files through your child theme or custom plugin and use Elementor only for the HTML structure.
Use the PHP code from the custom-code method above.
Make sure the loading condition includes the Elementor page where the slider will appear.
For example:
Replace 123 with the ID of your Elementor page.
123
Open the page with Elementor and drag an HTML widget into the desired section.
Paste the slider HTML structure into the widget.
Do not add separate <script> tags for Swiper inside every HTML widget. Loading the library through WordPress’s enqueue system is easier to maintain and reduces the risk of loading duplicate files.
Keep your CSS inside:
Keep the initialization script inside:
Update the page and preview it on the front end.
If you use an Elementor add-on that already provides a Swiper-powered widget, follow that plugin’s exact documentation instead. The controls and available features will depend on the specific add-on.
Once Swiper is working, you can adapt the slide content for different purposes.
Use one large image per slide.
An image slider works well for:
Use consistent image dimensions to avoid layout shifts.
Place an image, title, description, and button inside each slide.
A content carousel can display:
Each slide can contain:
Keep testimonials concise and provide enough time for visitors to read them before autoplay advances.
A blog carousel can display:
Developers can generate the slides dynamically with WP_Query rather than entering each post manually.
WP_Query
A product slider can show:
For dynamic product data, use a WooCommerce-compatible carousel plugin or build the slide markup through a custom WordPress query.
A logo slider is useful for displaying:
Use optimized SVG, WebP, or PNG files and provide meaningful alt text.
Portfolio slides can contain:
A Swiper portfolio carousel is particularly useful for agencies, designers, photographers, architects, event planners, and developers.
Swiper works well for moving between separate slides. It is not designed specifically for dragging a handle across two overlapping images.
For renovation results, photo editing, medical comparisons, design changes, or other side-by-side transformations, use a dedicated before-and-after image comparison slider instead.
Internal link opportunity: Add a contextual link to the WP Before After Image Slider product or a relevant before-and-after slider tutorial.
A responsive Swiper slider should not simply shrink the desktop layout. It should change the number of visible slides, spacing, text size, and controls according to the available screen width.
Swiper’s breakpoints option lets you change supported layout settings at specific screen widths.
breakpoints
Example:
breakpoints: { 640: { slidesPerView: 2, spaceBetween: 20, }, 1024: { slidesPerView: 3, spaceBetween: 24, }, 1280: { slidesPerView: 4, spaceBetween: 28, }, }
The default settings apply below the smallest breakpoint.
A fixed height may cause content to overflow on small screens.
Instead of forcing a height in JavaScript, use:
height: auto
autoHeight
Swiper’s documentation warns that forcing the JavaScript height parameter prevents normal responsive behavior.
height
A heading that fits on desktop may wrap onto three or four lines on a narrow screen.
Test:
Navigation buttons should have a sufficiently large clickable area. A control can have a small visual icon while still using a larger button container.
For most card-based sliders, one full slide or approximately 1.1 slides works well on mobile. Showing four tiny cards on a narrow screen makes the content difficult to read and interact with.
A slider should remain usable for visitors who navigate with keyboards, screen readers, reduced-motion settings, or enlarged text.
Describe the image’s purpose instead of stuffing the target keyword into every alt attribute.
Good example:
Responsive ecommerce homepage displayed on a laptop
Weak example:
Swiper slider WordPress image slider carousel plugin
Use an empty alt attribute for purely decorative images:
alt=""
Keyboard support lets users move through the slider without using a mouse or touch screen.
keyboard: { enabled: true, onlyInViewport: true, }
Swiper supports accessibility configuration for previous-slide and next-slide messages.
a11y: { enabled: true, prevSlideMessage: 'Previous slide', nextSlideMessage: 'Next slide', }
Do not remove the focus outline from buttons and links.
Make focus indicators easy to see against both light and dark slide backgrounds.
Some visitors prefer limited motion. Detect the prefers-reduced-motion setting and disable autoplay or shorten animations for those users.
prefers-reduced-motion
For important or text-heavy sliders, provide a visible pause button or disable autoplay entirely.
Avoid moving content that users cannot stop, especially when slides contain essential instructions.
Do not place important headings, prices, descriptions, or button labels inside an image. Real HTML text is easier to read, resize, translate, and navigate with assistive technology.
A slider can affect loading speed when it contains large images, videos, unnecessary scripts, or too many slides.
Before uploading an image:
Do not upload a 5,000-pixel image for a card displayed at 400 pixels wide.
Include width and height attributes:
<img src="project.webp" alt="Project dashboard interface" width="1200" height="675" >
This helps the browser reserve space before the image finishes loading.
When the slider is the main hero section, the first visible image may be an important loading element. Avoid lazy-loading that first image without testing the effect.
Use lazy loading for later slides:
<img src="project-two.webp" alt="Second project" width="1200" height="675" loading="lazy" >
Do not add 30 slides when most visitors will view only the first three.
Move large collections to a dedicated gallery or archive page.
Avoid loading the slider library across the entire website when only one landing page uses it.
Use WordPress conditional functions such as:
is_page() is_single() is_singular() is_front_page()
A theme, page builder, and plugin may each load a slider library.
Duplicate files can cause:
Check the browser’s Network tab for multiple copies of swiper-bundle.min.js or similar files.
swiper-bundle.min.js
Delay, defer, combine, or minification tools can improve performance, but an incorrect configuration may initialize your custom script before Swiper becomes available.
When the slider stops working after enabling optimization:
A background video can significantly increase page weight.
Use:
Swiper sliders may sometimes stop working because of missing files, incorrect settings, caching issues, or conflicts with themes and plugins. The following solutions will help you identify and fix the most common Swiper Slider problems in WordPress.
First, inspect the page source and confirm the required HTML classes exist:
swiper swiper-wrapper swiper-slide
Then check that the Swiper CSS, Swiper JavaScript, and initialization file are loaded.
Also:
This error usually means the custom initialization script ran before the main Swiper library loaded.
Check that:
array( 'swiper' )
is listed as a dependency of the custom JavaScript file.
Also avoid loading the library asynchronously when another script depends on its execution order.
This usually means the Swiper stylesheet is missing or blocked.
Confirm that:
swiper-bundle.min.css
appears in the Network tab and returns a successful response.
Also check whether a caching or security tool blocked the CDN.
Verify that the HTML contains:
<button class="swiper-button-prev"></button> <button class="swiper-button-next"></button>
Then confirm the JavaScript uses the correct elements:
navigation: { nextEl: slider.querySelector('.swiper-button-next'), prevEl: slider.querySelector('.swiper-button-prev'), }
When multiple sliders share global navigation selectors, the arrows may control the wrong slider. Initialize each slider separately and search for the controls inside its own container.
Check for this element:
<div class="swiper-pagination"></div>
Then enable pagination:
pagination: { el: slider.querySelector('.swiper-pagination'), clickable: true, }
Also check whether custom CSS hides the pagination or places it outside the visible container.
Check that autoplay is enabled:
autoplay: { delay: 5000, disableOnInteraction: true, }
Other possible causes include:
Looping requires enough slides for the selected slidesPerView and slidesPerGroup configuration. Swiper may also add blank slides in certain grouped or grid layouts.
slidesPerView
slidesPerGroup
If you display three slides at once, add more than three total slides before enabling loop mode.
Check for:
max-width: 100%
A useful starting rule is:
.codecanel-swiper { width: 100%; max-width: 100%; }
The following CSS intentionally crops images to a consistent ratio:
aspect-ratio: 16 / 9; object-fit: cover;
Use object-fit: contain when the full image must remain visible:
object-fit: contain
object-fit: contain; background: #f3f4f6;
Check whether a child element has a fixed width larger than the slider.
.codecanel-swiper, .codecanel-swiper * { box-sizing: border-box; }
Also confirm that the main slider container uses:
overflow: hidden;
Do not initialize every slider with one shared global navigation selector.
document.querySelectorAll('.codecanel-swiper').forEach((slider) => { new Swiper(slider, { navigation: { nextEl: slider.querySelector('.swiper-button-next'), prevEl: slider.querySelector('.swiper-button-prev'), }, }); });
This gives each slider its own controls.
Clear all caches first.
If the problem remains:
This can happen when a plugin’s assets are not detected in a custom template.
WP Swiper normally loads its front-end files when it detects its block. It also provides a global-loading option for templates or integrations that cannot be detected automatically.
Check the plugin settings, clear the cache, and inspect the page source for the required CSS and JavaScript.
Follow these guidelines before publishing:
There are two main ways to use Swiper Slider in WordPress.
The easiest option is a Gutenberg plugin such as WP Swiper. It lets content editors create responsive sliders with regular WordPress blocks and configure common features without writing code.
The custom-code method is better when you need complete control over the slider’s HTML, styling, breakpoints, performance, accessibility, or dynamic content. The same custom structure can also be added to an Elementor HTML widget after the Swiper assets have been correctly enqueued.
Whichever method you choose, focus on more than visual effects. Optimize your images, provide accessible navigation, respect reduced-motion preferences, test multiple screen sizes, and load the slider files only where they are needed.
A well-designed WordPress Swiper slider should help visitors discover content—not make important information harder to find.
Yes. The core Swiper JavaScript library is free and open source. WordPress plugins built with Swiper may offer their own free or paid features.
Swiper itself is a JavaScript library. WordPress developers can integrate the library manually, while plugins such as WP Swiper provide a WordPress-specific editor interface.
The best option depends on your editor and requirements. WP Swiper is suitable for Gutenberg users who want to place regular WordPress blocks inside slides. Elementor users may prefer an Elementor-specific carousel widget or a custom HTML implementation.Check that a plugin is actively maintained, compatible with your WordPress version, and provides the responsive and accessibility options you need.
Yes. Enqueue the Swiper CSS and JavaScript through a child theme or custom plugin, add the required HTML structure, and initialize the slider with JavaScript.
Yes. Use wp_enqueue_style() and wp_enqueue_script() inside a function attached to the wp_enqueue_scripts action.
wp_enqueue_style()
Enqueue Swiper through your child theme or functionality plugin, add the slider structure to an Elementor HTML widget, and keep the initialization script in a separate JavaScript file.
Yes. Gutenberg plugins such as WP Swiper allow you to create a slider directly inside the block editor and use nested WordPress blocks as slide content.
Only when your chosen plugin or custom code registers a shortcode. There is no universal Swiper WordPress shortcode. Copy the exact shortcode generated by your installed plugin instead of using a shortcode from an unrelated tutorial.
Give every slider the shared Swiper structure, then initialize each container separately with querySelectorAll().
querySelectorAll()
This page was last edited on 21 July 2026, at 6:39 pm
Your email address will not be published. Required fields are marked *
Comment *
Name *
Email *
Website
Save my name, email, and website in this browser for the next time I comment.
How many people work in your company?Less than 1010-5050-250250+
By proceeding, you agree to our Privacy Policy