year shortcode wordpress
To create a custom shortcode for the current year in WordPress, follow these steps:
- Access your WordPress dashboard.
- Go to the theme folder by navigating to "Appearance" > "Theme Editor."
- Find the "functions.php" file in the theme files list.
- Open the "functions.php" file.
- Add the following code snippet at the end of the file:
function current_year_shortcode() {
$year = date('Y');
return $year;
}
add_shortcode('year', 'current_year_shortcode');
- Save the changes by clicking on the "Update File" button.
- You've now created a shortcode
[year]
that will display the current year when used within WordPress.
After implementing these steps, the shortcode [year]
will dynamically output the current year wherever it is placed within your WordPress content.