{"id":34482,"date":"2019-08-23T14:25:55","date_gmt":"2019-08-23T14:25:55","guid":{"rendered":"http:\/\/getshortcodes.com\/?post_type=docs&#038;p=34482"},"modified":"2019-08-23T14:25:55","modified_gmt":"2019-08-23T14:25:55","slug":"replace-slider-and-carousel-with-image-carousel","status":"publish","type":"docs","link":"https:\/\/getshortcodes.com\/docs\/replace-slider-and-carousel-with-image-carousel\/","title":{"rendered":"How to replace Slider and Carousel shortcodes with the Image Carousel shortcode"},"content":{"rendered":"\n<p>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 <em>functions.php<\/em> file of your active theme.<\/p>\n\n\n\n<p>This code won&#8217;t replace old shortcodes in your posts or pages, but it will change the way they work.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>add_action( 'init', 'su_slider_carousel_to_image_carousel' );\n\nfunction su_slider_carousel_to_image_carousel() {\n\n\tremove_shortcode( su_get_shortcode_prefix() . 'slider' );\n\tremove_shortcode( su_get_shortcode_prefix() . 'carousel' );\n\n\tadd_shortcode(\n\t\tsu_get_shortcode_prefix() . 'slider',\n\t\t'su_slider_to_image_carousel'\n\t);\n\n\tadd_shortcode(\n\t\tsu_get_shortcode_prefix() . 'carousel',\n\t\t'su_carousel_to_image_carousel'\n\t);\n\n}\n\nfunction su_slider_to_image_carousel( $atts = null, $content = null ) {\n\n\t$atts = su_parse_shortcode_atts(\n\t\t'slider',\n\t\t$atts,\n\t\tarray( 'crop' => '3:2' )\n\t);\n\n\t$atts['source'] = str_replace( 'category:', 'taxonomy:category\/', $atts['source'] );\n\n\t$atts['dots']     = $atts['pages'];\n\t$atts['captions'] = $atts['title'];\n\n\tif ( 'no' === $atts['responsive'] ) {\n\t\t$atts['max_width'] = $atts['width'];\n\t}\n\n\tif ( 'yes' === $atts['centered'] ) {\n\t\t$atts['align'] = 'center';\n\t}\n\n\tif ( is_numeric( $atts['autoplay'] ) ) {\n\t\t$atts['autoplay'] = $atts['autoplay'] \/ 1000;\n\t}\n\n\tif ( $atts['speed'] > 600 ) {\n\t\t$atts['speed'] = 'fast';\n\t} elseif ( $atts['speed'] &lt; 600 ) {\n\t\t$atts['speed'] = 'slow';\n\t} else {\n\t\t$atts['speed'] = 'medium';\n\t}\n\n\treturn su_shortcode_image_carousel( $atts, $content );\n\n}\n\nfunction su_carousel_to_image_carousel( $atts = null, $content = null ) {\n\n\t$atts = su_parse_shortcode_atts(\n\t\t'carousel',\n\t\t$atts,\n\t\tarray( 'crop' => '3:2' )\n\t);\n\n\t$atts['source'] = str_replace( 'category:', 'taxonomy:category\/', $atts['source'] );\n\n\t$atts['dots']     = $atts['pages'];\n\t$atts['captions'] = $atts['title'];\n\t$atts['columns']  = $atts['items'];\n\n\tif ( 'no' === $atts['responsive'] ) {\n\t\t$atts['max_width'] = $atts['width'];\n\t}\n\n\tif ( 'yes' === $atts['centered'] ) {\n\t\t$atts['align'] = 'center';\n\t}\n\n\tif ( is_numeric( $atts['autoplay'] ) ) {\n\t\t$atts['autoplay'] = $atts['autoplay'] \/ 1000;\n\t}\n\n\tif ( $atts['speed'] > 600 ) {\n\t\t$atts['speed'] = 'fast';\n\t} elseif ( $atts['speed'] &lt; 600 ) {\n\t\t$atts['speed'] = 'slow';\n\t} else {\n\t\t$atts['speed'] = 'medium';\n\t}\n\n\treturn su_shortcode_image_carousel( $atts, $content );\n\n}<\/code><\/pre>\n","protected":false},"featured_media":0,"template":"","docs_category":[22],"class_list":["post-34482","docs","type-docs","status-publish","hentry","docs_category-troubleshooting"],"_links":{"self":[{"href":"https:\/\/getshortcodes.com\/api\/wp\/v2\/docs\/34482","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/getshortcodes.com\/api\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/getshortcodes.com\/api\/wp\/v2\/types\/docs"}],"wp:attachment":[{"href":"https:\/\/getshortcodes.com\/api\/wp\/v2\/media?parent=34482"}],"wp:term":[{"taxonomy":"docs_category","embeddable":true,"href":"https:\/\/getshortcodes.com\/api\/wp\/v2\/docs_category?post=34482"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}