Skip to content

Wrong date format for ACF date picker field #330

@josevarghese

Description

@josevarghese

Moved from Jira: https://yoast.atlassian.net/browse/IM-1818
Reporter: @amboutwe

Description
ACF includes a date picker field type. Yoast SEO automatically adds custom fields to the variable list. When adding the date picker ACF field to the title or description, the output uses the unformatted date instead of the format selected in ACF options.

This happens with or without the ACF + Yoast glue plugin.

Video: https://watch.screencastify.com/v/344zczyb1179n3of5ZDe

To Reproduce

Steps To Reproduce

Starting with a vanilla installation:

  1. Install and activate Advanced Custom Fields
  2. Create a custom field (steps below)
  3. Go to Admin > Posts > Add new
  4. Create a new post 'Yoast date test' and pick a date in the ACF metabox.
  5. Add some content and publish the post
  6. Go to Admin > Appearance > Theme File Editor
  7. Edit 'header.php' and add the lines below to the end of the file
  8. Click 'Update File'
  9. View post created with the above steps - See formatted date and unformatted date.
  10. Install and activate Yoast SEO (free)
  11. Edit post created with the above steps
  12. Add the 'Date (custom field)' variable at the start of the SEO title
  13. View post - See title has the unformatted date
  14. Install and activate ACF Content Analysis for Yoast SEO
  15. View post - See title still has the unformatted date

Create custom field

  1. Go to Admin > Custom fields > Add new
  2. Enter 'Yoast date test' in the title
  3. Click 'Add Field'
  4. Field Label = Date
  5. Field Name = date
  6. Field Type = Date picker
  7. Display Format = F j, Y
  8. Return Format = F j, Y
  9. Click 'Publish'

Add snippet to header.php

<?php
$pluginList = get_option( 'active_plugins' );
$plugin = 'advanced-custom-fields/acf.php'; 
if ( in_array( $plugin , $pluginList ) ) { ?>
<p style="margin-left: 3em">Date (no formatting): <?php the_field('date', false, false); ?> <br />Date (formatting): <?php the_field('date'); ?></p>
<?php }
?>

Expected Results

Date to use the display format from ACF

Actual Results

The unformatted date is shown

Impact
ACF users that want to show the ACF date field in the title or description.

WordPress version
: 5.9.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions