Last active
March 26, 2022 20:46
-
-
Save itsViney/0164908054ba969146335623aa7f24bd to your computer and use it in GitHub Desktop.
Wordpress shortcode based on Advanced Custom Fields' standard shortcode that adds the ability to specify a format for date fields.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Enhanced ACF date shortcode. Return format must be set to Ymd in ACF for this to work | |
Example: [acf_date field="my_date_field" post_id="1000" date_format="d F Y"] | |
*/ | |
function acf_date_shortcode($atts) | |
{ | |
extract(shortcode_atts(array( | |
'field' => '', | |
'post_id' => false, | |
'format_value' => true, | |
'date_format' => '' | |
), $atts)); | |
$acf_date = get_field($field, $post_id, $format_value); | |
$value = date_i18n($date_format, strtotime($acf_date)); | |
return $value; | |
} | |
add_shortcode('acf_date', 'acf_date_shortcode'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment