add_action(\’init\’, function () {
add_shortcode(\’formatted_start_date\’, function ($atts) {
$atts = shortcode_atts([\’id\’ => null], $atts);
$post_id = intval($atts[\’id\’]);
if (!$post_id) {
return \’\’;
}
$raw_date = get_field(\’start_date\’, $post_id);
if (!$raw_date) {
return \’\’;
}
// Try parsing as Ymd (ACF date format)
$date = DateTime::createFromFormat(\’Ymd\’, $raw_date);
if (!$date) {
// Try to parse other common formats just in case
$date = strtotime($raw_date);
if ($date) {
return date(\’M j, Y\’, $date); // fallback: Sep 16, 2025
} else {
return \”\”;
}
}
return $date->format(\’M j, Y\’); // Output: Sep 16, 2025
});
});