Do you want the text Copyright © Year ‘2020’ to be updated to the current year automatically in your WordPress footer? The best way to this is create a shortcode – without any plugins. With this I will also bring you a few bonus date formats like current date, current month and current day.
Step 1. Enable shortcodes in WordPress widgets
Place these few lines of code in your functions.php . If you do not have a child theme , you should get one first.
This will be overwritten next time you update your theme.
//Allow shortcodes in widgets
Step 2. Create your shortcode for the current year (and current month, current date or current day)
Next step is to create one or more shortcodes that display today’s date. Copy the code below for the date formats you want to use and paste it in your functions.php. You can place the code below the code you added in the previous step. Save.
//Display current year
function year_shortcode () {
$year = date_i18n (‘Y’);
return $year;
}
add_shortcode (‘year’, ‘year_shortcode’);
You will use [ year ] to display the year
//Display current month
function monthyear_shortcode () {
$monthyear = date_i18n (‘F’);
return $monthyear;
}
add_shortcode (‘monthyear’, ‘monthyear_shortcode’);
You will use [ mounth ] to display the year
//Display current date as YYYY-MM-DD
function yyyymmdd_shortcode () {
$yyyymmdd = date_i18n (‘y-m-d’); return $yyyymmdd;
}
add_shortcode (‘yyyymmdd’, ‘yyyymmdd_shortcode’);
You will use [ yyyymmdd ] to display the year
//Display current month and year
function monthyear_shortcode () {
$monthyear = date_i18n (‘F Y’);
return $monthyear;
}
add_shortcode (‘monthyear’, ‘monthyear_shortcode’);
You will use [ year ] to display the year
//Display current day
function day_shortcode () {
$day = date_i18n (‘l’);
return $day;
}
add_shortcode (‘day’, ‘day_shortcode’);
You will use [ day ] to display the year
3. Add “Copyright © 2020 Company Name. All rights reserved.” in your footer
editing your footer should look something like this: