Stop Updating Years in Business on Your WordPress Site with this Shortcode

Years in Business Shortcode for WordPress

One of the greatest things about WordPress is the flexibility to build out shortcodes. Shortcodes are basically substitution strings that you can insert into your content that renders dynamic content.

I’m helping a client this week where they’re taking one of their products and rolling it out into a new domain. The site is hundreds of pages and has been quite an undertaking. As we’ve been working on the hit list of issues, one that popped up was that there were dozens of blog posts, pages, and calls-to-action that spoke to the company’s years in business.

Some pages had 13, some 15, others were accurate at 17… all depending upon when they were written. This is one of those unnecessary edits to need to make that a shortcode can handle perfectly.

All we need to do is register a shortcode that takes the current year and subtracts it from the year the company was established. We can register the shortcode and put the function within the site’s theme’s functions.php file:

function YIB_shortcode() {
   $start_year = '2003';
   $current_year = date('Y');
   $displayed_year = $current_year - $start_year;
   $years = $displayed_year;
   return $years;
add_shortcode('YIB', 'YIB_shortcode');

What the function does is subtract the current year from 2003 to come up with the appropriate number of years that the company has been in business.

So, if I wish to write how long the company has been in business within the content of the site, I just write:

Our company has been in business for [YIB]+ years!

Of course, you can get far more complex with this type of shortcode… you could use HTML, images, CSS, etc. but this is just a simple example to just make sure your site is already accurate!

What do you think?

This site uses Akismet to reduce spam. Learn how your comment data is processed.