The Lodge is members-only design/dev videos and Office Hours.

Next Office Hours Session: "Implementing an SVG Icon System" Nov 30 - 6:00 PM Eastern

Year Shortcode

Last updated on:

For the functions.php file:

function year_shortcode() {
  $year = date('Y');
  return $year;
add_shortcode('year', 'year_shortcode');


Use [year] in your posts.


  1. J. DeForest

    Thanks! That code works great!!!

  2. Jamaima
    Permalink to comment#

    Nice, works like a charm. Thanks for sharing this useful tip.

  3. JackLee
    Permalink to comment#

    Copyright © $starty){echo $starty.’-‘.$nowy;}else{echo $nowy;} }else{ echo date(“Y”);} ?> . All Rights Reserved.

  4. JackLee
    Permalink to comment#

    Copyright © <?php date_default_timezone_set(PRC); $starty=get_option(‘cwpcg_starty’);
    $nowy=date(“Y”); if(get_option(‘cwpcg_starty’)){ if($nowy>$starty){echo $starty.’-‘.$nowy;}else{echo $nowy;} }else{ echo date(“Y”);} ? > <?php bloginfo(‘name’); ? >. All Rights Reserved.

  5. Kevin
    Permalink to comment#

    Awesome! Just what I was looking for.

Leave a Comment

Posting Code

We highly encourage you to post problematic HTML/CSS/JavaScript over on CodePen and include the link in your post. It's much easier to see, understand, and help with when you do that.

Markdown is supported, so you can write inline code like `<div>this</div>` or multiline blocks of code in in triple backtick fences like this:

  function example() {
    element.innerHTML = "<div>code</div>";

There's a whole bunch of content on CSS-Tricks.

Search for Stuff   •   Browse the Archives

Get the Newsletter ... or get the RSS feed