How To Make A Dynamic Number Value Update Automatically Each Year In Divi Tutorial by Pee Aye Creative

How To Make A Dynamic Number Value Update Automatically Each Year In Divi

Nelson Miller Pee Aye Creative
In this tutorial I will show you how to make a number value update automatically each year in Divi, perfect for number of years in business!
Categories: Divi PHP Tutorials

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!




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.

showing dynamic number of years in Divi headline

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:

adding the php code for the dynamic Divi number


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!

Last updated [last-modified %date%]


Each month we send out a roundup email newsletter with the latest tutorials, product updates, helpful resources, and any other industry or personal news. Occasionally we send an extra separate email here and there if we just can’t wait! So that’s what you will get if you subscribe, and you can always unsubscribe at any time if you just can’t take it anymore :)

Blog Post Optin

Please share this post!

Nelson Lee Miller (aka The Divi Teacher)

Nelson is the owner of Pee-Aye Creative in the beautiful state of Pennsylvania. He loves helping small businesses, exploring outdoors, building websites with Divi, and teaching others.

Leave A Response!

By commenting you agree to our Blog & YouTube Comments Policy


  1. Ronnie

    Is there a way to make shortcodes work in the Divi Customiz > Footer > Footer Bar – Edit Footer Credits. Thanks

    • Nelson Lee Miller (aka The Divi Teacher)

      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.

      • Ronnie

        Thanks Nelson

Submit a Comment

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

Recent Posts


Your Cart