How to Add the Current Dynamic Copyright Year in WordPress Using functions.php
If you want to keep your WordPress website up-to-date, one important aspect is to ensure that the copyright year in the footer reflects the current year. This not only shows that your site is actively maintained, but it also provides a sense of credibility to your visitors. In this tutorial, we’ll walk you through the process of adding the current copyright year dynamically using code in the functions.php
file.
Step 1: Access Your WordPress Dashboard
Log in to your WordPress dashboard by navigating to www.yourwebsite.com/wp-admin
and entering your credentials.
Step 2: Open the functions.php File
- In the dashboard, go to Appearance > Theme File Editor.
- On the right-hand side, you’ll see a list of files. Look for
Theme Functions (functions.php)
. - Click on
Theme Functions (functions.php)
to open the file.
Step 3: Add the PHP Code
Now, you’ll need to add a few lines of PHP code that will automatically update the copyright year. The second bit of code generates a shortcode, making it easier to place in different parts of your website.
function year_shortcode () {
$year = date_i18n ('Y');
return $year;
}
add_shortcode ('year', 'year_shortcode');
Paste this code at the end of your functions.php
file.
Step 4: Save Changes
After adding the code, make sure to save the file by clicking on the “Update File” button at the bottom of the code editor.
Step 5: Place the Shortcode
Go to the section of your site that houses your footer code. Most themes have a Footer option in the settings. Sometimes there is a Footer Widget. Paste in the shortcode 2024
and check your site for the current date.
You’ve successfully added dynamic copyright year functionality to your WordPress website. This small but important detail helps maintain the professionalism and credibility of your site.
Remember, always make a backup of your functions.php
file before making any changes. This ensures that you can easily revert to the previous version if anything goes wrong.
If you encounter any issues or have questions, feel free to ask for help in the WordPress support forums or consult with a developer.
Interested in more? Learn how to restrict access to your website with .htaccess.