Programmatically change the content of the carousel items


In this tutorial, you’ll see how to programmatically change the carousel items content so you can display complex content such as shortcodes, array custom fields, taxonomies, etc…

Edit the file “functions.php” of your theme/child theme and copy/paste the exemplary code below, then, adapt it to your needs:

$post_id: The ID of the post. Use it to get your post data.

$default_content: The default carousel items content .

function my_custom_carousel_description($default_content, $post_id){

	$custom_content = '';
	
	$name_custom_field = get_post_meta($post_id, "YOUR_CUSTOM_FIELD_NAME", true);
	$address_custom_field = get_post_meta($post_id, "YOUR_CUSTOM_FIELD_NAME", true);
	$website_custom_field = get_post_meta($post_id, "YOUR_CUSTOM_FIELD_NAME", true);		
	
	$custom_content .= '<strong>Name: </strong>' . $name_custom_field. '<br />';
	$custom_content .= '<strong>Address: </strong>' . $address_custom_field . '<br />';
	$custom_content .= '<strong>Website: </strong><a href="'.$website_custom_field.'">Visit</a>';
	
	return $custom_content;
		
}
add_filter('cspm_custom_item_description', 'my_custom_carousel_description', 10, 2);

In the same context