Add a Dynamic Date to Gutenberg, ACF Fields, and Contact Form 7

Dynamic dates show up on almost every WordPress site — most often in the footer copyright line, but also in post content, ACF fields, Contact Form 7 forms, and email templates. The typical approach is to hardcode the year and update it manually every January, which developers invariably forget. WordPress shortcodes solve this cleanly: register a single [dynamic_date] shortcode that accepts a PHP date format string, and the output updates automatically on every page load. The same shortcode works in the Gutenberg editor via the Shortcode block, in Classic Editor, in ACF WYSIWYG fields out of the box, and in ACF text/textarea fields with a one-line filter. For Contact Form 7, one additional filter enables shortcode processing inside form markup. This article also covers using ACF’s own shortcode syntax — [acf field="field_name"] — inside CF7 forms, which is useful when you need to pull a field value from the current page rather than a PHP date format.

Problem: The copyright year (or any other date) in your WordPress theme, ACF fields, or Contact Form 7 forms is hardcoded and must be updated manually every year.

Solution: Register a [dynamic_date] shortcode that accepts any PHP date format character. Enable shortcode processing in ACF text fields and Contact Form 7 with one filter each.

Add to functions.php:

<?php
add_shortcode( 'dynamic_date', 'custom_dynamic_date' );

function custom_dynamic_date( $atts ) {
    $atts = shortcode_atts( [ 'date' => 'Y' ], $atts );
    return esc_html( date( $atts['date'] ) );
}

// Enable shortcodes in ACF text fields
add_filter( 'acf/format_value/type=text',     'do_shortcode' );
// Enable shortcodes in ACF textarea fields
add_filter( 'acf/format_value/type=textarea', 'do_shortcode' );
// Enable shortcodes inside Contact Form 7 form markup
add_filter( 'wpcf7_form_elements',            'do_shortcode' );

Usage in content, Gutenberg Shortcode block, or ACF fields:

© [dynamic_date date="Y"] My Company   <!-- outputs: © 2020 My Company -->
[dynamic_date date="F j, Y"]              <!-- outputs: January 5, 2020 -->
[dynamic_date date="d/m/Y"]               <!-- outputs: 05/01/2020 -->

To dynamically inject an ACF field value — for example, a property ID — into a Contact Form 7 form, use ACF's own shortcode tag (no custom shortcode needed, just ensure wpcf7_form_elements runs do_shortcode):

[hidden property-id id:property-id]
[acf field="property_id"]

NOTE: The date() function outputs the date in the server's timezone. If your site serves visitors in multiple timezones and the date shown must match the visitor's local time, use wp_date() instead — it respects the timezone set in Settings → General. For the copyright year use case, server timezone is almost always fine.

Sources:

  1. https://support.advancedcustomfields.com/forums/topic/shortcodes-in-text-field/
  2. https://wordpress.stackexchange.com/questions/45266/how-to-use-other-shortcodes-inside-contact-form-7-forms
  3. https://www.php.net/manual/en/datetime.format.php