Site icon Bernard Aybout's Blog – MiltonMarketing.com

Dynamic WordPress: Displaying Current Year with PHP Code

Dynamic WordPress Displaying Current Year with PHP Code

Dynamic WordPress Displaying Current Year with PHP Code

📘 Displaying the Current Year in WordPress (Without Hardcoding!)

Why It Matters:

Using dynamic dates (like the current year) ensures your copyright footers and date-based references stay up to date automatically—boosting professionalism and reducing manual updates.


✅ Method 1: Using functions.php (Safe Theme-Based Method)

👨‍💻 Step-by-Step:

  1. Access Your Theme’s functions.php File:

    • Go to your WordPress Admin Dashboard.

    • Navigate to Appearance → Theme File Editor.

    • Click on functions.php under the active theme (usually called Theme Functions).

  2. Add This Code:

Copy to Clipboard
  1. Use the Shortcode Anywhere:

    • In posts, pages, or widgets:
      [current_year]

    • In template files (like footer.php), use:
      php echo do_shortcode('[current_year]');

⚠️ Notes:

  • This code is theme-specific. If you change themes, you’ll need to re-add it.

  • Always backup your site before editing PHP files!


✅ Method 2: Using the “Code Snippets” Plugin (Best Practice for Non-Devs)

🔧 Why This is Safer:

Using a plugin like Code Snippets lets you run PHP code without touching theme files, so changes persist even if you switch themes.

🛠 How to Do It:

  1. Install the Plugin:

    • Go to Plugins → Add New.

    • Search for Code Snippets.

    • Install and activate it.

  2. Add a New Snippet:

    • Go to Snippets → Add New.

    • Title it: Display Current Year Shortcode.

  3. Paste This Code:

Copy to Clipboard
  1. Save and Activate the Snippet.

  2. Use the Shortcode:

    • Anywhere in your post or page, insert:
      [current_year]


🔄 Use Case Examples

  • Copyright Footer:

Copy to Clipboard

In Legal Pages or Dynamic Templates:

Copy to Clipboard

Inside Widgets:

  • Add a Text Widget or use Avada’s Custom HTML Block with:

Copy to Clipboard
  • No Hardcoded Dates: Google appreciates content that’s clearly maintained. Auto-updating your year reflects recency.

  • Structured Footers: Use semantic HTML (<footer>) and microdata for site info when possible.

  • Avoid Overuse in Headings: Don’t place [current_year] in <h1> unless contextually appropriate.


🏁 Summary

Method Best For Theme-Dependent
functions.php Developers customizing a child theme ✅ Yes
Code Snippets Editors, safer plugin approach ❌ No

📌 Bonus Tip: Auto-Update Copyright Footer

If you want to combine your site name + year dynamically:

Copy to Clipboard

Use this as [site_footer] in footers or widget areas.


Related Videos:

Bernard Aybouts - Blog - MiltonMarketing.com

Related Posts:

Show Popular Posts Without Plugins

Pro PHP Security, 2nd Edition

What is a Shortcode in WordPress?

WordPress by the Numbers Facts

WordPress PayPal Donation Shortcode: Easy Buttons & Plugins

What is a Shortcode in WordPress?

Enhance WordPress: TinyMCE Buttons & Shortcode Plugins

Pro PHP Security, 2nd Edition

Maximize WordPress SEO: Posts vs Pages & Content Strategy

PHP

Behind the Screens

Introduction to JavaScript

Disable Search in WordPress

How to Update: Automatically create media_buttons for shortcode selection

Should I Choose a Hosted or Non-hosted Blogging Platform?

What is a Blog?

How to Define surcharge by country with WooCommerce

Custom WooCommerce Code for Cart Fees & Surcharges

Create a PayPal Donation Shortcode – WordPress

Redirect New Registered Users to a Specific Page – WordPress

FAQ Hacked WordPress Website

The background-color CSS property

How do I start a WordPress blog? (hosting wordpress)

How do I install plugins in WordPress?

WordPress, SEO, and Social Media Marketing

WordPress Posts vs Pages

Introduction to Python Programming Language

Change the Author Permalink Structure – WordPress

Choose your preferred blog CMS platform

Why Python is the cooler programming language

Comparing Python to other languages

Helping humans speak to the computer

The Python Standard Library Ver 3.6.5

Learn more about JavaScript Variables

Learn Code Introspection Python Programming

Learn about programming Loops in Python

Learn Partial functions Python programming

Tips and Tricks for WRITING JAVASCRIPT code

Learn about programming Functions in Python

Learn about Numpy Arrays in Python programming

CODING WITH CSS: The style attribute

Learn about Python Generators

Learn about programming Classes and Objects in Python

Python String Formatting

Introduction to JavaScript – Variables: String Interpolation

Learn List Comprehensions in Python Programming

Learn about Python Conditions

Methods of teaching programming

Exit mobile version