How to replace Slider and Carousel shortcodes with the Image Carousel shortcode

If you want to replace old Slider and Carousel shortcodes with the new Image Carousel shortcode, just add the following code to the end of the functions.php file of your active theme.

This code won’t replace old shortcodes in your posts or pages, but it will change the way they work.

add_action( 'init', 'su_slider_carousel_to_image_carousel' );

function su_slider_carousel_to_image_carousel() {

	remove_shortcode( su_get_shortcode_prefix() . 'slider' );
	remove_shortcode( su_get_shortcode_prefix() . 'carousel' );

	add_shortcode(
		su_get_shortcode_prefix() . 'slider',
		'su_slider_to_image_carousel'
	);

	add_shortcode(
		su_get_shortcode_prefix() . 'carousel',
		'su_carousel_to_image_carousel'
	);

}

function su_slider_to_image_carousel( $atts = null, $content = null ) {

	$atts = su_parse_shortcode_atts(
		'slider',
		$atts,
		array( 'crop' => '3:2' )
	);

	$atts['source'] = str_replace( 'category:', 'taxonomy:category/', $atts['source'] );

	$atts['dots']     = $atts['pages'];
	$atts['captions'] = $atts['title'];

	if ( 'no' === $atts['responsive'] ) {
		$atts['max_width'] = $atts['width'];
	}

	if ( 'yes' === $atts['centered'] ) {
		$atts['align'] = 'center';
	}

	if ( is_numeric( $atts['autoplay'] ) ) {
		$atts['autoplay'] = $atts['autoplay'] / 1000;
	}

	if ( $atts['speed'] > 600 ) {
		$atts['speed'] = 'fast';
	} elseif ( $atts['speed'] < 600 ) {
		$atts['speed'] = 'slow';
	} else {
		$atts['speed'] = 'medium';
	}

	return su_shortcode_image_carousel( $atts, $content );

}

function su_carousel_to_image_carousel( $atts = null, $content = null ) {

	$atts = su_parse_shortcode_atts(
		'carousel',
		$atts,
		array( 'crop' => '3:2' )
	);

	$atts['source'] = str_replace( 'category:', 'taxonomy:category/', $atts['source'] );

	$atts['dots']     = $atts['pages'];
	$atts['captions'] = $atts['title'];
	$atts['columns']  = $atts['items'];

	if ( 'no' === $atts['responsive'] ) {
		$atts['max_width'] = $atts['width'];
	}

	if ( 'yes' === $atts['centered'] ) {
		$atts['align'] = 'center';
	}

	if ( is_numeric( $atts['autoplay'] ) ) {
		$atts['autoplay'] = $atts['autoplay'] / 1000;
	}

	if ( $atts['speed'] > 600 ) {
		$atts['speed'] = 'fast';
	} elseif ( $atts['speed'] < 600 ) {
		$atts['speed'] = 'slow';
	} else {
		$atts['speed'] = 'medium';
	}

	return su_shortcode_image_carousel( $atts, $content );

}
Helpful?
🤝 Thank you!