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.
Want to create a beautiful image carousel in WordPress without installing another heavy slider plugin?
A custom Slick Slider is a great option when you want full control over your slider design, layout, speed, navigation arrows, dots, responsiveness, and dynamic content. Whether you want to display images, testimonials, blog posts, portfolio items, or WooCommerce products, Slick Slider gives you a flexible way to create smooth, mobile-friendly sliders inside your WordPress website.
In this guide, you’ll learn how to create a custom Slick Slider in WordPress without a plugin. We’ll cover the basic setup, how to enqueue Slick Slider files properly, how to add slider markup, how to make it responsive, how to create a shortcode, how to display dynamic WordPress posts, and how to fix common Slick Slider issues.
By the end, you’ll have a working custom slider that you can use inside your WordPress theme, template files, shortcode areas, Elementor pages, Gutenberg blocks, or WooCommerce sections.
Slick Slider is a popular jQuery-based carousel library that lets you create responsive sliders, image carousels, content sliders, testimonial sliders, and product sliders.
In WordPress, Slick Slider is commonly used to create:
The main advantage of using Slick Slider in WordPress is flexibility. Instead of depending on a ready-made slider plugin, developers can control the HTML, CSS, JavaScript, and dynamic WordPress query.
WordPress slider plugins are helpful, especially for beginners. But sometimes, a plugin may add too many extra features, scripts, or styling options that you do not need.
A custom Slick Slider is better when you want:
However, if you are not comfortable editing code, using a slider plugin may be easier. A custom Slick Slider is best for users who can work with WordPress theme files, shortcodes, and basic JavaScript.
Before creating a custom Slick Slider in WordPress, make sure you have:
Important note: Avoid editing your main parent theme directly. If the theme updates, your custom code may be removed. Always use a child theme or a site-specific custom plugin.
First, you need to add Slick Slider files to your WordPress theme.
Download Slick Slider and place the files inside your child theme like this:
your-child-theme/ │ ├── assets/ │ ├── slick/ │ │ ├── slick.css │ │ ├── slick-theme.css │ │ └── slick.min.js │ │ │ └── js/ │ └── slick-init.js
You can also use a CDN, but for better control, loading the files locally from your theme is usually better.
Now, you need to load the Slick Slider CSS and JavaScript files properly in WordPress.
Open your child theme’s functions.php file and add this code:
functions.php
function codecanel_enqueue_slick_slider_assets() { // Slick Slider CSS wp_enqueue_style( 'slick-css', get_stylesheet_directory_uri() . '/assets/slick/slick.css', array(), '1.8.1' ); // Slick Slider Theme CSS wp_enqueue_style( 'slick-theme-css', get_stylesheet_directory_uri() . '/assets/slick/slick-theme.css', array('slick-css'), '1.8.1' ); // Slick Slider JS wp_enqueue_script( 'slick-js', get_stylesheet_directory_uri() . '/assets/slick/slick.min.js', array('jquery'), '1.8.1', true ); // Custom Slick Initialization JS wp_enqueue_script( 'custom-slick-init', get_stylesheet_directory_uri() . '/assets/js/slick-init.js', array('jquery', 'slick-js'), '1.0.0', true ); } add_action('wp_enqueue_scripts', 'codecanel_enqueue_slick_slider_assets');
This code loads the Slick Slider CSS, theme CSS, Slick JavaScript file, and your custom initialization file.
The array('jquery') dependency ensures that jQuery loads before Slick Slider. This is important because Slick Slider depends on jQuery.
array('jquery')
Next, add the slider HTML where you want the slider to appear.
You can place this code inside a WordPress template file such as:
front-page.php
page.php
single.php
home.php
Here is a basic image slider structure:
<div class="custom-slick-slider"> <div class="slider-item"> <img src="https://example.com/image-1.jpg" alt="WordPress custom slick slider image 1"> </div> <div class="slider-item"> <img src="https://example.com/image-2.jpg" alt="WordPress custom slick slider image 2"> </div> <div class="slider-item"> <img src="https://example.com/image-3.jpg" alt="WordPress custom slick slider image 3"> </div> <div class="slider-item"> <img src="https://example.com/image-4.jpg" alt="WordPress custom slick slider image 4"> </div> </div>
Replace the image URLs with your own image links from the WordPress Media Library.
Now open your slick-init.js file and add this code:
slick-init.js
jQuery(document).ready(function($) { $('.custom-slick-slider').slick({ infinite: true, slidesToShow: 3, slidesToScroll: 1, dots: true, arrows: true, autoplay: true, autoplaySpeed: 3000, speed: 600, pauseOnHover: true }); });
This will activate the slider on any element with the class custom-slick-slider.
custom-slick-slider
Here is what the settings mean:
infinite: true
slidesToShow: 3
slidesToScroll: 1
dots: true
arrows: true
autoplay: true
autoplaySpeed: 3000
pauseOnHover: true
Now add some CSS to style your custom Slick Slider.
You can place this CSS inside your child theme’s style.css file or in the WordPress Customizer under Appearance > Customize > Additional CSS.
style.css
.custom-slick-slider { margin: 40px auto; max-width: 1200px; } .custom-slick-slider .slider-item { padding: 10px; } .custom-slick-slider .slider-item img { width: 100%; height: 300px; object-fit: cover; border-radius: 12px; display: block; } .custom-slick-slider .slick-prev, .custom-slick-slider .slick-next { z-index: 10; } .custom-slick-slider .slick-dots { bottom: -35px; }
This makes the images responsive, gives them equal height, adds spacing between slides, and improves the overall appearance.
A good WordPress slider should look clean on desktops, tablets, and mobile devices.
Update your slick-init.js file with responsive breakpoints:
jQuery(document).ready(function($) { $('.custom-slick-slider').slick({ infinite: true, slidesToShow: 3, slidesToScroll: 1, dots: true, arrows: true, autoplay: true, autoplaySpeed: 3000, speed: 600, pauseOnHover: true, responsive: [ { breakpoint: 1024, settings: { slidesToShow: 2, slidesToScroll: 1 } }, { breakpoint: 600, settings: { slidesToShow: 1, slidesToScroll: 1, arrows: false } } ] }); });
With this setup:
This is useful when creating a responsive Slick Slider in WordPress without a plugin.
If you want to display your slider anywhere using a shortcode, you can create a custom WordPress shortcode.
This is useful when you want to add your Slick Slider inside:
Add this code to your child theme’s functions.php file:
function codecanel_slick_slider_shortcode($atts) { $atts = shortcode_atts( array( 'ids' => '', ), $atts, 'codecanel_slick_slider' ); if (empty($atts['ids'])) { return ''; } $image_ids = explode(',', $atts['ids']); ob_start(); ?> <div class="custom-slick-slider shortcode-slick-slider"> <?php foreach ($image_ids as $image_id) : $image_id = intval($image_id); $image_url = wp_get_attachment_image_url($image_id, 'large'); $image_alt = get_post_meta($image_id, '_wp_attachment_image_alt', true); if ($image_url) : ?> <div class="slider-item"> <img src="<?php echo esc_url($image_url); ?>" alt="<?php echo esc_attr($image_alt); ?>"> </div> <?php endif; endforeach; ?> </div> <?php return ob_get_clean(); } add_shortcode('codecanel_slick_slider', 'codecanel_slick_slider_shortcode');
Now you can use this shortcode:
[codecanel_slick_slider ids="12,25,38,41"]
Replace the numbers with your WordPress Media Library image IDs.
This is one of the easiest ways to create a custom Slick Slider shortcode in WordPress.
To use the shortcode above, you need the image IDs from the WordPress Media Library.
Follow these steps:
item=
Example:
post.php?post=25&action=edit
Here, the image ID is 25.
25
You can also create a dynamic Slick Slider using WordPress posts.
This is useful if you want to display your latest blog posts in a carousel.
Add this code to your template file:
<?php $slider_query = new WP_Query(array( 'post_type' => 'post', 'posts_per_page' => 6, 'post_status' => 'publish', )); if ($slider_query->have_posts()) : ?> <div class="custom-slick-slider post-slick-slider"> <?php while ($slider_query->have_posts()) : $slider_query->the_post(); ?> <div class="slider-item post-slider-item"> <a href="<?php the_permalink(); ?>"> <?php if (has_post_thumbnail()) : ?> <?php the_post_thumbnail('large'); ?> <?php endif; ?> <h3><?php the_title(); ?></h3> </a> </div> <?php endwhile; ?> </div> <?php endif; wp_reset_postdata(); ?>
Add some CSS:
.post-slider-item { background: #ffffff; border-radius: 12px; overflow: hidden; box-shadow: 0 8px 25px rgba(0, 0, 0, 0.08); } .post-slider-item img { width: 100%; height: 220px; object-fit: cover; } .post-slider-item h3 { font-size: 18px; line-height: 1.4; padding: 16px; margin: 0; } .post-slider-item a { text-decoration: none; color: inherit; }
This creates a dynamic WordPress post carousel using Slick Slider.
If your website has a portfolio, testimonials, services, or case studies, you may want to create a Slick Slider from a custom post type.
For example, if your custom post type is portfolio, use this code:
portfolio
<?php $portfolio_slider = new WP_Query(array( 'post_type' => 'portfolio', 'posts_per_page' => 8, 'post_status' => 'publish', )); if ($portfolio_slider->have_posts()) : ?> <div class="custom-slick-slider portfolio-slick-slider"> <?php while ($portfolio_slider->have_posts()) : $portfolio_slider->the_post(); ?> <div class="slider-item portfolio-slider-item"> <a href="<?php the_permalink(); ?>"> <?php if (has_post_thumbnail()) : ?> <?php the_post_thumbnail('large'); ?> <?php endif; ?> <div class="portfolio-content"> <h3><?php the_title(); ?></h3> <p><?php echo wp_trim_words(get_the_excerpt(), 15); ?></p> </div> </a> </div> <?php endwhile; ?> </div> <?php endif; wp_reset_postdata(); ?>
You can replace portfolio with your own custom post type name.
Examples:
'post_type' => 'testimonial' 'post_type' => 'case_study' 'post_type' => 'service' 'post_type' => 'project'
This method is perfect for creating a dynamic custom post type slider in WordPress.
If you use Advanced Custom Fields, you can create a custom image slider using ACF repeater fields.
For example, create an ACF repeater field called:
slider_images
Inside the repeater, add an image field called:
slider_image
Then add this code to your template file:
<?php if (have_rows('slider_images')) : ?> <div class="custom-slick-slider acf-slick-slider"> <?php while (have_rows('slider_images')) : the_row(); $image = get_sub_field('slider_image'); if ($image) : $image_url = $image['url']; $image_alt = $image['alt']; ?> <div class="slider-item"> <img src="<?php echo esc_url($image_url); ?>" alt="<?php echo esc_attr($image_alt); ?>"> </div> <?php endif; endwhile; ?> </div> <?php endif; ?>
This is helpful when you want a different slider for each page or post.
For example, you can use ACF Slick Slider for:
There are two simple ways to add a custom Slick Slider in Elementor.
If you created the shortcode earlier, simply add this shortcode inside Elementor’s Shortcode widget:
This is the easiest method because you do not need to add HTML directly inside Elementor.
You can also add your slider markup inside Elementor’s HTML widget:
<div class="custom-slick-slider"> <div class="slider-item"> <img src="https://example.com/image-1.jpg" alt="Elementor slick slider image 1"> </div> <div class="slider-item"> <img src="https://example.com/image-2.jpg" alt="Elementor slick slider image 2"> </div> <div class="slider-item"> <img src="https://example.com/image-3.jpg" alt="Elementor slick slider image 3"> </div> </div>
Make sure your Slick Slider CSS and JS files are already enqueued in your WordPress theme. Otherwise, the slider will not work.
You can use Slick Slider to create a WooCommerce product carousel.
This is useful for displaying:
Here is a simple WooCommerce product slider shortcode.
function codecanel_woocommerce_product_slider_shortcode($atts) { $atts = shortcode_atts( array( 'limit' => 8, 'category' => '', ), $atts, 'codecanel_product_slider' ); $args = array( 'post_type' => 'product', 'posts_per_page' => intval($atts['limit']), 'post_status' => 'publish', ); if (!empty($atts['category'])) { $args['tax_query'] = array( array( 'taxonomy' => 'product_cat', 'field' => 'slug', 'terms' => sanitize_text_field($atts['category']), ), ); } $product_query = new WP_Query($args); ob_start(); if ($product_query->have_posts()) : ?> <div class="custom-slick-slider woocommerce-slick-slider"> <?php while ($product_query->have_posts()) : $product_query->the_post(); global $product; ?> <div class="slider-item product-slider-item"> <a href="<?php the_permalink(); ?>"> <?php if (has_post_thumbnail()) : ?> <?php the_post_thumbnail('woocommerce_thumbnail'); ?> <?php endif; ?> <h3><?php the_title(); ?></h3> <?php if ($product) : ?> <div class="product-price"> <?php echo wp_kses_post($product->get_price_html()); ?> </div> <?php endif; ?> </a> </div> <?php endwhile; ?> </div> <?php endif; wp_reset_postdata(); return ob_get_clean(); } add_shortcode('codecanel_product_slider', 'codecanel_woocommerce_product_slider_shortcode');
[codecanel_product_slider limit="8"]
Or display products from a specific category:
[codecanel_product_slider limit="8" category="t-shirts"]
Add this CSS for better product slider design:
.product-slider-item { background: #ffffff; padding: 16px; border-radius: 12px; text-align: center; box-shadow: 0 8px 25px rgba(0, 0, 0, 0.08); } .product-slider-item img { width: 100%; height: auto; margin-bottom: 12px; } .product-slider-item h3 { font-size: 17px; margin: 10px 0; } .product-slider-item a { text-decoration: none; color: inherit; } .product-price { font-weight: 600; margin-top: 8px; }
This lets you create a custom WooCommerce product carousel with Slick Slider.
Sometimes Slick Slider may not work properly in WordPress because of script loading issues, jQuery conflicts, missing CSS, or incorrect initialization.
Here are the most common problems and how to fix them.
wp_enqueue_script()
slick.css
$ is not a function
jQuery(document).ready(function($) {})
slick-theme.css
object-fit: cover
This is one of the most common Slick Slider errors in WordPress.
Usually, it happens because:
To fix this, make sure your enqueue code has the correct dependencies:
wp_enqueue_script( 'custom-slick-init', get_stylesheet_directory_uri() . '/assets/js/slick-init.js', array('jquery', 'slick-js'), '1.0.0', true );
Also, make sure your initialization code uses WordPress-friendly jQuery syntax:
jQuery(document).ready(function($) { $('.custom-slick-slider').slick(); });
Do not write only this in WordPress:
$(document).ready(function() { $('.custom-slick-slider').slick(); });
WordPress often runs jQuery in no-conflict mode, so using $ directly may cause errors unless it is properly passed into the function.
$
Here are some common Slick Slider settings you can use:
slidesToShow
3
slidesToScroll
1
autoplay
true
autoplaySpeed
3000
dots
arrows
infinite
speed
600
pauseOnHover
fade
centerMode
adaptiveHeight
responsive
array
Example with more advanced settings:
jQuery(document).ready(function($) { $('.advanced-slick-slider').slick({ slidesToShow: 3, slidesToScroll: 1, infinite: true, dots: true, arrows: true, autoplay: true, autoplaySpeed: 4000, speed: 700, pauseOnHover: true, centerMode: false, adaptiveHeight: false, responsive: [ { breakpoint: 992, settings: { slidesToShow: 2 } }, { breakpoint: 576, settings: { slidesToShow: 1, arrows: false } } ] }); });
To make your custom Slick Slider perform better, follow these best practices.
Large images can slow down your slider and affect page speed. Before uploading images to WordPress, compress them and use the correct size.
For example, if your slider image displays at 600px wide, avoid uploading a 3000px image unless needed.
Every image should have meaningful alt text. This helps with accessibility and image SEO.
<img src="slider-image.jpg" alt="Custom Slick Slider example in WordPress">
Do not add too many slides unless necessary. A slider with 5 to 8 slides is usually enough for most sections.
Too many slides can make the page heavier and reduce user engagement.
Always test your slider on mobile devices. Make sure:
WordPress supports lazy loading for images by default in many cases. You can also add the loading attribute manually:
<img src="image.jpg" alt="Slider image" loading="lazy">
This helps improve loading performance.
If you only use Slick Slider on one or two pages, do not load the files across the entire website.
You can conditionally enqueue the files on specific pages:
function codecanel_enqueue_slick_conditionally() { if (is_front_page() || is_page('gallery')) { wp_enqueue_style( 'slick-css', get_stylesheet_directory_uri() . '/assets/slick/slick.css', array(), '1.8.1' ); wp_enqueue_script( 'slick-js', get_stylesheet_directory_uri() . '/assets/slick/slick.min.js', array('jquery'), '1.8.1', true ); } } add_action('wp_enqueue_scripts', 'codecanel_enqueue_slick_conditionally');
This can help reduce unnecessary CSS and JavaScript loading.
A custom Slick Slider is not always the right choice for everyone. Sometimes, a plugin is faster and easier.
Here is a quick comparison:
If your goal is to show normal image carousels, testimonials, posts, or products, a custom Slick Slider can be a good solution.
But if your goal is to show image comparisons, such as before-and-after results, design changes, editing samples, beauty transformations, real estate renovations, or product improvements, a before-after image comparison plugin is more suitable.
For that use case, you can use WP Before After Image Slider by CodeCanel. It helps you create interactive before-and-after sliders in WordPress without coding and lets users compare two images with a draggable handle.
You should create a custom Slick Slider in WordPress when:
A custom Slick Slider is especially useful for developers building custom WordPress websites.
You should use a WordPress slider plugin when:
For non-technical users, a plugin is usually easier. For developers, a custom Slick Slider gives more control.
Creating a custom Slick Slider in WordPress is a great way to add a responsive, lightweight, and fully customizable carousel to your website without depending on a heavy plugin.
With Slick Slider, you can build image sliders, blog post carousels, portfolio sliders, testimonial sliders, WooCommerce product sliders, ACF sliders, and custom post type sliders. You can also create shortcodes to display your slider anywhere on your website.
The key steps are simple:
If you are comfortable with code, this method gives you full control over your WordPress slider. But if you need a visual image comparison slider, especially for before-and-after images, a dedicated plugin like WP Before After Image Slider can save time and make the process easier.
Whether you choose custom code or a plugin, the main goal is the same: create a smooth, user-friendly slider that improves your website design and helps visitors engage with your content.
To create a custom Slick Slider in WordPress, download the Slick Slider files, add them to your child theme, enqueue the CSS and JS files using wp_enqueue_style() and wp_enqueue_script(), add slider HTML markup, and initialize the slider with jQuery.
wp_enqueue_style()
Yes, you can add Slick Slider in WordPress without a plugin. You need to manually add the Slick Slider files to your theme, enqueue them properly, and write custom HTML and JavaScript to initialize the slider.
You can enqueue Slick Slider by adding wp_enqueue_style() and wp_enqueue_script() functions inside your theme’s functions.php file. Make sure jQuery loads before the Slick Slider JS file.
Your Slick Slider may not work because the JS file is missing, jQuery is not loaded, files are loading in the wrong order, the slider class name is incorrect, or another plugin is causing a JavaScript conflict.
To fix “slick is not a function,” make sure Slick Slider JS is loaded after jQuery and before your custom initialization file. Also, use jQuery(document).ready(function($) {}) instead of using $ directly.
You can make Slick Slider responsive by using the responsive option in your Slick initialization code. Add breakpoints for desktop, tablet, and mobile screen sizes.
Yes, you can create a custom shortcode in WordPress using add_shortcode(). This lets you display your Slick Slider inside posts, pages, Elementor, Gutenberg, and widget areas.
add_shortcode()
Yes, you can use Slick Slider with Elementor. The easiest way is to create a shortcode and place it inside Elementor’s Shortcode widget. You can also add slider HTML inside an Elementor HTML widget.
Yes, Slick Slider works well with ACF repeater fields. You can create a repeater field for slider images and loop through those fields inside your WordPress template.
Yes, you can create a WooCommerce product carousel using Slick Slider. You can query products using WP_Query and display them inside a custom Slick Slider layout.
WP_Query
This page was last edited on 6 July 2026, at 1:07 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