I’m trying to modify slidestoshow
parameter in CoBlocks Carousel block via my theme’s functions. Everything in the Codex implies modifying/passing the variable but looking at the code, it appears it’s an [anonymous function?] Forgive me if this term is incorrect.
I’ve tried both apply_filters()
and add_filters()
to replace the entire array rather than the individual key/value. I’ve tried removing the existing filter and adding it again but I’m not sure if the way it’s coded is preventing me from making my modification.
Do I need to call the plugin Class CoBlocks_Settings
?
Here is the original plugin code:
$ block_content = sprintf( '<div class="%1$ s"><div class="coblocks-slick pb-8" data-slick="%2$ s">', esc_attr( $ class ), esc_attr( wp_json_encode( /** * Filter the slick slider carousel settings * * @var array Slick slider settings. */ (array) apply_filters( 'coblocks_post_carousel_settings', array( 'slidesToScroll' => 1, 'arrow' => true, 'slidesToShow' => $ attributes['columns'], 'infinite' => true, 'adaptiveHeight' => false, 'draggable' => true, 'responsive' => array( array( 'breakpoint' => 1024, 'settings' => array( 'slidesToShow' => 3, ), ), array( 'breakpoint' => 600, 'settings' => array( 'slidesToShow' => 2, ), ), array( 'breakpoint' => 480, 'settings' => array( 'slidesToShow' => 1, ), ), ), ) ) ) ) );
First, I tried just overriding it with:
apply_filters( 'coblocks_post_carousel_settings', array( ... ));
Second, here’s where I’m at in Functions:
apply_filters( 'coblocks_post_carousel_settings', 'my_filter_coblocks_carousel' ); function my_filter_coblocks_carousel() { $ carousel = array( 'slidesToScroll' => 1, 'arrow' => true, 'slidesToShow' => $ attributes['columns'], 'infinite' => true, 'adaptiveHeight' => false, 'draggable' => true, 'responsive' => array( array( 'breakpoint' => 1024, 'settings' => array( 'slidesToShow' => 4, ), ), array( 'breakpoint' => 600, 'settings' => array( 'slidesToShow' => 4, ), ), array( 'breakpoint' => 480, 'settings' => array( 'slidesToShow' => 4, ), ), ), ); return $ carousel; }