Current year shortcode for printing copyright notice in WordPress

Did you ever want a quick way to print a nice footer with the copyright in years?

Here’s a shortcode for that! Put it in your themes functions.php and use anywhere!

add_shortcode('copyright-year', function($atts, $content)
        'sign' => 'true',
        'start' => '',
    ), $atts));

    $current_year = date('Y');
    $print_sign = ($sign === 'true') ? '©' : '';

    if($start === $current_year || $start === '')
        return "{$print_sign} {$current_year}";
        return "{$print_sign} {$start} - {$current_year}";




Result: © 2020

Without copyright sign

[copyright-year sign="false"]    

Result: 2020

With copyright sign and a “start year”.

[copyright-year sign="true" start="2012"]

Result: © 2012 - 2020

Leave a Reply

Your email address will not be published. Required fields are marked *

Markdown is allowed in comments.