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
add_filter ('widget_text', 'do_shortcode');
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
2024
//Display current month
function monthyear_shortcode () {
$monthyear = date_i18n ('F');
return $monthyear;
}
add_shortcode ('monthyear', 'monthyear_shortcode');
You will use [ month ] to display the Month
November
//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 Date by numbers
24-11-21
//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 date
November 2024
//Display current day
function day_shortcode () {
$day = date_i18n ('l');
return $day;
}
add_shortcode ('day', ‘day_shortcode');