Add a Dynamic Copyright Year in WordPress
Do you need an automatic way to display the current year in your WordPress copyright notice? Here’s how to implement this using the Code Snippets plugin – no direct file editing is required!
Prerequisites
- WordPress installed
- Code Snippets plugin installed and activated
- You can find it in the WordPress plugin repository by searching for “Code Snippets”
Implementation Steps
- In your WordPress dashboard, go to Snippets → Add New
- Name your snippet something descriptive like “Dynamic Year Shortcode”
- Copy and paste this code into the snippet editor:
function current_year() {
$year = date('Y');
return $year;
}
add_shortcode('year', 'current_year');
- Under “Snippet Type,” ensure “PHP Function” is selected
- Click the “Save Changes and Activate” button
Using Your New Shortcode
Now you can use the [year]
shortcode anywhere in your WordPress site. For example:
© [year] Your Website Name. All rights reserved.
Place this in your footer widget or footer template, and it will automatically display the current year.
Why Use Code Snippets?
- Safe: No need to edit theme files directly
- Portable: Snippets remain even if you change themes
- Organized: All your custom code in one manageable place
- User-friendly: Easy to activate/deactivate when needed
Troubleshooting
If the shortcode isn’t working:
- Make sure the snippet is activated
- Verify there are no syntax errors in the code
- Check that the shortcode is properly formatted with square brackets
[year]
That’s all there is to it! Now you have a maintenance-free way to display the current year anywhere on your WordPress site.