I'm trying to put the Date Published and Date Modified into the meta tags of the head of the header.php page - so far no luck.

This is what I currently have:

<meta name="date" content="<?php echo get_the_date( 'm-d-Y' ); ?>">
<meta name="revised" content="<?php echo the_modified_date( 'm-d-Y' ); ?>">

I've also left off the get_ with the_date but that didn't work either. I've tried the_date. I've tried without the echo.

I assume that since the header.php is pulled on each post and page, and that these dates are pulled in the Admin area that these should already in the Loop without needing to add to the functions.php. If I do need to add this can someone assist me with the code to put into the file and which file?

When I do an analysis at http://analyzer.metatags.org/ the page shows:

Status:         200 OK
Last update:    Thu, 01 Jan 1970 00
Web Server:     Apache
Content Type:   text/html; charset=UTF-8

I really don't want to use a plugin. I'd rather learn how to do it.

I understand how to put this into a post or page but I can't get it right in the header.php.

You can check if is_singular page/post and then use global $post to get the post ID outside the loop. Also for the modified date you should use get_the_modified_date instead because you're already echoing.

<?php if(is_singular()): ?>
    <?php global $post; ?>
    <meta name="date" content="<?php echo get_the_date( 'm-d-Y', $post->ID ); ?>">
    <meta name="revised" content="<?php echo get_the_modified_date( 'm-d-Y', $post->ID ); ?>">
 <?php endif; ?>
  • I tried this on a page and on a post and I still get: Last update: Thu, 01 Jan 1970 00 – learning2 Jul 21 '17 at 23:15
  • And what do you have on the page source of those pages/posts? What do you have on those meta fields? – dbeja Jul 21 '17 at 23:17
  • Yes, I inspected the head with the 'right click' and found that the dates were there. Thank you! – learning2 Jul 21 '17 at 23:28
  • Great! Maybe it's just cache on metatags.org. – dbeja Jul 21 '17 at 23:30
  • I think revised meta tag is not much used: stackoverflow.com/questions/33889445/… – dbeja Jul 21 '17 at 23:47

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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