Find Current Year in WordPress

Website design

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:

  1. Functions.php Approach:

    Add the following code to your theme’s functions.php file:

    function current_year_shortcode() {
    $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
  2. Usage in Footer:

    In your footer file (footer.php), you can add the shortcode wherever you want to display the current year:

    <p>&copy; [current_year] Your Website Name. All rights reserved.</p>

    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.



Leave a Comment

Your email address will not be published. Required fields are marked *