How to use dynamic date to WordPress editor

Did you know about dynamic date are using on 99,9% all sites. Where, you ask? As a rule, in the footer, in the Copyright section. But, on almost sites, this section doing as hardcode. And in this case use dynamic date it’s no problem. In this article we’ll review how add dynamic date to the content section from admin dashboard.

How to add dynamic date to Gutenberg, ACF, Contact Form 7

Problem: How to add dynamic date to Gutenberg, ACF, Contact Form 7, etc

Solution: Adding current time or date (day, month, year) to title or description in WordPress it's simple. For this should be use shortcode. In functions.php you should be add next code:

<?php
// Dynamic Date Shortcode
add_shortcode( 'dynamic_date', 'custom_dynamic_date' );

function custom_dynamic_date( $atts ) {
	return date( $atts['date'] );
}

In the editor, you can use next shortcode:

[dynamic_date date="F"]

Also, it works for WYSIWYG ACF fields. For text ACF fields, you should be add next filter to functions.php:

<?php
add_filter('acf/format_value/type=text', 'do_shortcode');

And for textarea ACF fileds:

<?php
add_filter('acf/format_value/type=textarea', 'do_shortcode');

For Contact Form 7 fields:

<?php
add_filter( 'wpcf7_form_elements', 'do_shortcode' );

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

Leave Comment

Your email address will not be published.