Programmatically change the title of the infobox


In this tutorial, you’ll see how to programmatically change the infobox’s title so you can display complex title 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_title: The default infobox title.

function my_custom_infobox_title($default_title, $post_id){

	$custom_title = '';
	
	$first_name_custom_field = get_post_meta($post_id, "YOUR_CUSTOM_FIELD_NAME", true);
	$last_name_custom_field = get_post_meta($post_id, "YOUR_CUSTOM_FIELD_NAME", true);
	$age_custom_field = get_post_meta($post_id, "YOUR_CUSTOM_FIELD_NAME", true);		
	
	$custom_title .= $first_name_custom_field . $last_name_custom_field . ', ' . $age_custom_field .' years';
	
	return $custom_title;
		
}
add_filter('cspm_custom_infobox_title', 'my_custom_infobox_title', 10, 2);

In the same context