Shortcoding: Dates

I see so many websites with HTML footers containing expired copyright dates. You shouldn’t have to remember to update the year all the time.

To avoid ever having to think about this, use a shortcode in a theme to add a data anywhere. Add the following code to your functions.php file:

// date shortcode -- for putting in footers and text
function date_shortcode( $atts ) {
   extract(shortcode_atts(array(
       'id' => '',
   ), $atts));
   return date($id);
}
add_shortcode('date', 'date_shortcode');

Then just call any current date formate. For the current year, simple add the following right in your text editor:

[thedate id="Y"] 

But change “thedate” to “date” if you use the code I provided. I changed it to “thedate” so the shortcode wouldn’t execute.