Auto-Updating Dynamic Year Number
It is common to display the number of years a company has been in business on their website, especially on an about page. If you write something like “In Business For 21 Years” it sounds nice, but the next year it immediately becomes outdated, and no one has time to remember to update it each year. The alternative is to write “Since (year)” but that’s not as cool. So in this tutorial I will show you how to make a number value update automatically each year in Divi using a shortcode and snippet.
Join subscribers on our YouTube channel and enjoy other Divi video tutorials!
1. Add The Shortcode
The first step will be to start with a shortcode. The shortcode will be powered by a snippet, which we will talk about in step #2. The shortcode needs to be placed within the HTML of the text wherever you want the dynamic number to appear. Below is the shortcode, so copy that and go to your website and add it to your text.
Be sure to watch the video for this tutorial, it will really help!
Shortcode
[pa_dynamic_years_number]
Example
I’ll show you an example of this. It would be the same for a headline or paragraph. Go to the Text module or any other Divi module that supports HTML and click on the “Text” tab, which means HTML. Place the shortcode within the text as shown.

2. Add The PHP Code
The second step now is to add the PHP code that is working behind the scenes and connected to the shortcode. This involves pasting the PHP code snippet below into your website. There are a number places to add this, and it will totally depend on your website and experience.
If you have a child theme, then you would add this snippet to the functions.php file of a Divi child theme. If you don’t already have one, you can download our free Divi child theme here.
If you want the easy way, then I will recommend installing the Code Snippets plugin. It is a great plugin that allows you to add snippets easily in the backend of your admin area. After activating, just go to Snippets>Add New, write a title, paste the snippet, and click the save and activate button. Here is how that will look:

Snippet
add_shortcode( 'pa_dynamic_years_number', 'pa_dynamic_years_shortcode' );
function pa_dynamic_years_shortcode() {
$start_date = new DateTime('2000-1-1');
$current_date = new DateTime();
$interval = $start_date->diff($current_date);
return $interval->format('%y');
}
Edit The Date
The only part that you should edit is the date. You can look for 2000-1-1. This is in the YEAR-MONTH-DAY format, so just change the year, month, and date to whatever you want. This is when the number starts counting.
It’s a little hard to show a good screenshot of this one, so be sure to watch the video to get the live demonstration!
Is there a way to make shortcodes work in the Divi Customiz > Footer > Footer Bar – Edit Footer Credits. Thanks
I don’t know the answer to that, but I would highly recommend just switching to the Divi Theme Builder instead. The Customizer will be extinct soon.
Thanks Nelson