Skip to content Skip to sidebar Skip to footer

Conditional Slick-carousel Carousel Setting

Is it possible to only add a setting to something like carousel options if a value exists? If arrowsposition is empty, null etc, instead of appendArrows still being used, could I r

Solution 1:

To achieve this you can create the settings object first, then add the appendArrows property if needed in your if statement:

var slickSettings = {
  arrows: true,
  dots: false
}

if (typeof contentblockData === 'object') {
  slickSettings.appendArrows = $('.' + contentblockData.data);
} else {
  console.log('No contentblock data available, make sure \'contentblockData\' is available via wp_localize_script');
}

$(this).slick(slickSettings)

Post a Comment for "Conditional Slick-carousel Carousel Setting"