Published: April 19, 2023

|   Written by Scott Minnis

In this tutorial, we’ll show you how to create a dynamic shortcode for your WordPress website that will display the number of years a company has been in business. This shortcode will automatically update each year, so you don’t need to change it manually. We’ll use the example of a company that has been in business since 1999.

Step 1

Locate your theme’s functions.php file To add a custom shortcode to your WordPress website, you’ll need to edit your theme’s functions.php file. To do this:

  1. Log in to your WordPress admin dashboard.
  2. Navigate to Appearance > Theme Editor.
  3. In the right sidebar, locate and click on the functions.php file to open it in the editor.

Step 2

Add the custom shortcode code Copy and paste the following code at the end of your functions.php file:

This code defines a new shortcode called company_years that calculates the difference between the current year and the start year (1999) and returns the result.

Step 3

Save your changes After adding the code to your functions.php file, click the “Update File” button to save your changes.

Step 4

Use the shortcode in your posts, pages, or widgets You can now use the [company_years] shortcode in your posts, pages, or widgets to display the number of years the company has been in business. Simply insert the shortcode wherever you want the number to appear, and it will automatically update each year.

For example, you could write a sentence like this in your post or page editor:

Our company has been proudly serving customers for [company_years] years!

When the page is displayed, the [company_years] shortcode will be replaced with the number of years the company has been in business.

Conclusion

In this tutorial, we’ve shown you how to create a dynamic “Years in Business” shortcode for your WordPress website. By adding a simple piece of code to your theme’s functions.php file, you can display the number of years a company has been in operation with ease. This shortcode will automatically update each year, ensuring that your website stays accurate and up-to-date without any manual intervention.