Programmatically change the content of the infobox


In this tutorial, you’ll see how to programmatically change the infobox’s 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 infobox content .

function my_custom_infobox_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_infobox_description', 'my_custom_infobox_description', 10, 2);

In the same context