我正在尝试修改slidestoshow
通过“我的主题”的函数在CoBlocks Carousel块中设置参数。Codex中的所有内容都意味着修改/传递变量,但看看代码,它似乎是一个[匿名函数?]如果这个术语不正确,请原谅我。
我两个都试过了apply_filters()
和add_filters()
替换整个数组而不是单个键/值。我已经尝试删除现有的过滤器并再次添加,但我不确定它的编码方式是否阻止我进行修改。
我需要调用插件类吗CoBlocks_Settings
?
以下是原始插件代码:
$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,
),
),
),
)
)
)
)
);
首先,我尝试用以下内容覆盖它:
apply_filters( \'coblocks_post_carousel_settings\', array( ... ));
其次,这里是我在函数中的位置:
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;
}