Many companies and websites strive for accuracy when it comes to the content of their website. It is easy to forgot about minor details such as the copyright year which is typically displayed within the footer of a website. Lets make that dynamic for you, its super simple using the WordPress Shortcode API.

Add the following code to your WordPress Themes functions.php file

add_shortcode('copyright-year', 'dynamicCopyrightYear');
function dynamicCopyrightYear() {
      return date('Y');
}

The above snippet will build your shortcode, allowing you to use it within the CMS and theme files.

Lets quickly break it down so you understand the functionality behind it.

  • The 'add_shortcode' is a WordPress hook.
  • The hook returns the result of the specified function to the defined shortcode.
  • The dynamicCopyrightYear function is simply returning the current Year utilizing the built in date PHP function.

To add it to a Widget (Appearance -> Widgets), Post, Page or other CMS content simply use the shortcode below:

[copyright-year]

To add it to one of your theme files, simply use the shorthand PHP code below:

<php echo do_shortcode['[copyright-year]']; ?>

Code Snippet By

Mike Biegalski


Biegalski LLC

Bio

A professional full stack developer, having experience in all aspects of the development cycle. Actively diving into new technology just to experience the workflow and see how it functions.

Submit An Article

We are open to accepting articles written by members of the community. If you have a quality article that you would like featured please, submit the article here.