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:

// 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:

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

And for textarea ACF fileds:

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

For Contact Form 7 fields:

add_filter( 'wpcf7_form_elements', 'do_shortcode' );

UPDATE 22.02.2023

Also we can use default shortcodes from ACF. For example we need change title of a submit button at Contaсt Form 7. For resolve we:

  1. At the current page create ACF field, e.g. form_button_title
  2. At the contact form 7 settings of form add [acf field="form_button_title"]
  3. In the functions.php file add features shortcodes in Contact Form 7

add_filter( 'wpcf7_form_elements', 'do_shortcode' );



Leave Comment

Your email address will not be published. Required fields are marked *