Add a dynamic date in a divi code module

Last updated Apr 20, 2021

Update: If you are not comfortable with using code to setup a dynamic date in divi, I have another post showing you how to do the same but without adding code.

If you are not familiar with a dynamic date, it is a date that is dynamically generated by the server. A good use case is your copyright notice at the bottom of your website. Using a dynamic date, you will not have to update that every year as it will be dynamically updated by the server.

Add a dynamic date in a divi code module
Use a dynamic date in the footer of your divi website

Thankfully, if you are like me and are too lazy or have too many clients to update every year, it is relatively easy to setup to do so automatically.

Add a Dynamic Date in a Divi Code Module

You will need a child theme and access to the functions.php file to use the code snippet.

Copy and paste the code below into your functions.php file

function displayTodaysDate( $atts ) {
  $year = date('Y');
  return $year;
    }
    add_shortcode( 'datetoday', 'displayTodaysDate');

Now you can add a Divi Code module anywhere in your site and call the date by adding the following into your code module

[shortcodename] in our example above it would be datetoday

If you want to display it in a better format, you could use the following;

Copyright © [shortcodename] Sitename

Just remember to change “Sitename” to your actual site’s name.

And that is it! From now on, you will no longer have to update that footer date as it will be dynamically managed by the code you have entered above.

Subscribe to keep informed

You're busy, I get it. Who has time to visit the site daily to see if there are new tutorials? Make your life easier by subscribing to the monthly newsletter where you will get a summary of all the posts uploaded that month.