Home › Forums › General Issues › Displaying shortcode of date_picker with format › Reply To: Displaying shortcode of date_picker with format
Hi ! I also add an error generated with the above code, so I modified it using the date_i18n function so the date will be translated corresponding to your language. (it worked with wpml)
Please note that for this to work, the format of your acf date field (for template) must be this type :
20211010 Ymd
As above, the syntax of the Shortcode is the same :
[acf_date field='date_field' date_format='M j, 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' );
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.