How to find Current Year in WordPress for footer dynamic ?
In WordPress, you can create a shortcode to dynamically display the current year in your footer. Here’s how you can do it:
-
Functions.php Approach:
Add the following code to your theme’s
function current_year_shortcode() {functions.php
file:
$year = date(‘Y’);
return $year;
}
add_shortcode(‘current_year’, ‘current_year_shortcode’);
This code defines a shortcode[current_year]
that will output the current year -
Usage in Footer:
In your footer file (
<footer>footer.php
), you can add the shortcode wherever you want to display the current year:
<p>© [current_year] Your Website Name. All rights reserved.</p>
</footer>
Whenever the page loads, WordPress will replace
[current_year]
with the current year, ensuring that your footer always displays the correct copyright information.Remember, modifying theme files directly is not recommended as it can be overwritten during theme updates. Consider creating a child theme or using a custom plugin to add custom functionality to your WordPress site.