How can you test a WordPress copyright year that is generated dynamically or through PHP, meaning when the year changes without waiting an entire year to see if it changes? I do not know anything about virtual containers or anything like that, so try to go easy on me here. If that's what it requires then show me in a simple way how I can test this.

I had bought a WordPress theme that did not come with a copyright year that would auto update. So I asked the developer for a script that would do so and placed it in the functions.php file in my child theme folder. So when the year changed from 2019 to 2020 the year did not flip over.

Here is the original code given to me.

    function child_theme_footer_text() {
    echo get_the_date( 'Y' );
    add_action( 'gridbox_footer_text', 'child_theme_footer_text' );

It did not work. I then changed the code from that to this :

    function child_theme_footer_text() {
    echo date( "Y" );
    add_action( 'gridbox_footer_text', 'child_theme_footer_text' );

As you can see I changed echo get_the_date( ‘Y’ ); to echo date( “Y”);

I also changed the single quotes to double quotes around the Y. This changed the date but it could have changed just as easily by simply removing and then placing back the original code and I would still never know if it is actually working or not.

I do not think that changing the echo get_the_date( ‘Y’ ); to echo date( “Y”); actually did anything at all and I only thought it did. I think that just reset it as if I was inserting the code for the very first time.

Also, the actual file name in the folder of my WP child theme is named gridbox-child. I asked the developer if I was supposed to change the name or slug from child_theme to the actual name of my child theme and he said I should. I am not entirely sure why I never changed this but I am planning on doing that right now. The problem is that I still would never know if it is working or not.

So without changing anything from what was given to me except the name of the child theme I am guessing the correct code would look something like this :

    function gridbox-child_footer_text() {
    echo get_the_date( 'Y' );
    add_action( 'gridbox_footer_text', 'child_theme_footer_text' );

There is a dash instead of an underscore in the gridbox-child name. So I assume this is what is supposed to be used.

The two main questions are 1. Would this work correctly? If not then what would? and 2. How would I ever know?

  • The year represents the initial date the claim was made, aka how far back the copyright claim goes, so by updating it every year you relinquish another year of copyright. Do not change the year! If you do change it, move it further into the past not the future! stackoverflow.com/questions/2390230/… Also copyright claims are a US thing, everybody outside the USA is automatically covered, and copyright is automatic, no copyright statement is needed
    – Tom J Nowell
    Commented Mar 11, 2020 at 12:34

1 Answer 1


Putting aside the legal issues, and focusing on a function for displaying the current year, the problem is actually pretty straightforward: The theme developer gave you the wrong code.

  • get_the_date( 'Y' ) gets the year of the publication date of the current post. This is not what you asked for.
  • date( 'Y' ) is a native PHP function that gets the current date and time on on the server. This is what they were probably meant to give you.
  • wp_date( 'Y' ) is a newer function (WordPress 5.3) that will get the current date and time, accounting for your timezone setting in WordPress. This is the one you'd be better off using.

This really isn't something you should need to test. There's no good reason that date() or wp_date() shouldn't work. If you need assurances, I suggest testing each of these with a different format, so that you can at least see that they reflect the current day. If you use 'r' instead of 'Y' you will see a date like this:

Thu, 12 Mar 2020 09:30:00 +0200

If that date is not correct 2 days in a row, then the function you're using won't give you the correct year.

Ultimately this isn't something that should be your responsibility to test. You just need the right information, and you weren't given it. Now that you have the right information, you can rely on the PHP and WordPress developers to have done the testing to make sure their functions give the right dates.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.