Subscribe On YouTube

Join other subscribers and enjoy other Divi video tutorials!

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

Nelson Miller Profile Orange
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!

▶️ Please watch the video above to get all the exciting details! 👆

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.

Where To Paste The PHP Code

1. Divi Assistant
If you are using our Divi Assistant plugin, simply paste the code in the PHP tab in the custom code window in the Divi Visual Builder.

2. Child Theme
If you are using a child theme, paste this code into the functions.php file. If you don't have a child theme, you can generate a child theme directly on your site or download our free child theme.

3. Code Snippet Plugins
Otherwise, install a dedicated code snippet plugin, create a new snippet, and paste this code into the PHP code editor.

If you need help understanding where to paste the code, please check out our complete guide about where to add custom PHP code snippets in Divi.


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!

Categories: Divi PHP Tutorials

Subscribe For More Things Like This!

At the start of each month, we send out a recap newsletter from the month before with family news, Divi news, our latest tutorials, and product news. Occasionally, if the news is too exciting to wait, we will send out another email separate from the monthly newsletter. That’s what you get when you subscribe, and of course you can unsubscribe if you are no longer interested!

Blog Post Optin

Leave A Response!

By commenting you agree to our Blog & YouTube Comments Policy


Comments By Others

  1. James Hayward

    This worked a treat. I was able to modify the code and have it calculate. In the future.
    Here is the code if anyone wants to try. Basically I wanted it to display next month’s date for a rolling deadline we had on the website.

    add_shortcode( ‘pa_dynamic_month_plus_4weeks’, ‘pa_dynamic_month_shortcode’ );
    function pa_dynamic_month_shortcode() {
    $current_date = new DateTime();
    $current_date->modify(‘+4 weeks’);
    return $current_date->format(‘F’);

    • Hemant Gaba

      Thank you for sharing the code.

  2. Ronnie

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

      • Ronnie

        Thanks Nelson

Submit a Comment

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

Recent Posts


Your Cart