phpwordpressdategenesis

How do I correct an incorrect year shown in a WordPress Genesis website footer?


This may be pretty specific & a bit of a newb question but PHP is one of my weaker areas - I think I know what's causing the problem, I'm just not sure what to replace it with. The issue looks like get_the_date() shows the date that the post (page, etc) was created, rather than the current date. I've been poring over the documentation on the_date (https://developer.wordpress.org/reference/functions/the_date/) but I haven't figured out what I should replace get_the_date( 'Y' ) with & I think it's partially because of the shorthand that we've used on our function, which took me a couple hours to put together, I'm afraid.

Here's what we're currently using:

// Custom Footer Credits
add_filter('genesis_footer_creds_text', 'custom_footer_creds_filter');
function custom_footer_creds_filter( $editthecredit ) {
  $editthecredit = 'Copyright © ';
  $editthecredit .= get_the_date( 'Y' );
  $editthecredit .= ' ';
  $editthecredit .= get_bloginfo( 'name' );
  return $editthecredit ;
}
// End Footer Credits

The issue is that get_the_date( 'Y' ) returns the date that the page was created. I've seen where folks have used echo get_the_date( 'Y' ) but that breaks the site.

I thought at first it was because we may need to deregister the default Genesis footer so I used some of Brian Gardner's advice here (https://studiopress.blog/customize-genesis-site-footer/) but it made no difference.


Solution

  • WordPress' the_date functions are intended to show the date of the current Loop item (Post, Page, etc).

    If you want today's date, use PHP's default date function. For example, the following prints out today's year:

    echo date('Y');
    

    specifically for your case:

    $editthecredit .= date('Y');