Home Forums Gutenberg Initilize swiper slider in editor (gutenberg)


Initilize swiper slider in editor (gutenberg)

  • I’m trying to build woo-commerce slider block with swiper slider (not slick)
    I’m having trouble initializing the slider in the editor, it does no work and the script does not run in the backend editor,

    var mySwiper = new Swiper('.product-slider', {
    // Optional parameters
        slidesPerView: 4,
        spaceBetween: 30,
        paginationClickable: true,
        loop: true,
        autoplay: {
            delay: 3000,
        // Navigation arrows
        pagination: {
            el: '.swiper-pagination',
            type: 'bullets',
            clickable: true
    var initializeBlock = function( $block ) {
    // Initialize each block on page load (front end).
            initializeBlock( $(this) );
    // Initialize dynamic block preview (editor).
    if( window.acf ) {
        window.acf.addAction( 'render_block_preview/type=featured-product', initializeBlock );
  • Any progress with this? Facing the same problem.

  • I didn’t find an answer anywhere so I posting what works for me.

    Call the swiper instance inside a window.load.


    var initializeBlock = function( $block ) {

    The same principle can be used with vanilla using window.addEventListener('load').

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.