Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

Header: Include Date Published and Date Modified

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; ?>

Related Posts:

  1. Why won’t wp_mail() let me set the From: header when plain old PHP mail() will?
  2. How does one suppress a 404 status code in a WordPress page?
  3. Admin bar and fixed header issue?
  4. How to remove rest api link: in http headers?
  5. disable wordpress canonical tag meta
  6. Disable h1 and h2 from rich text editor combobox
  7. Recommended location to set response headers?
  8. Is it safe to fix Access-Control-Allow-Origin (CORS origin) errors with a php header directive?
  9. Custom endpoint and X-WP-TotalPages (headers)
  10. Getting “Cannot modify header information – headers already sent” error on wp-admin only whenever any plugin is activated
  11. Additional Option on Custom Header admin
  12. How can I use CURLOPT_USERPWD in wp_remote_post?
  13. Putting content into header.php without using wp_head
  14. Setting Last Modified HTTP Header on static Home Page
  15. Permalinks using event date (year & month) instead of publication date
  16. If Modified Since HTTP Header
  17. Clean up output added via wp_head()
  18. Ordering posts by anniversary using only day and month
  19. Human Time Diff, change mins to minutes
  20. Image slider to display at the very top of home page
  21. Remove rel=shortlink from HTTP header
  22. Getting redirect to happen before header output
  23. How do you log a user out with wp_logout?
  24. Indenting (tabbing) WP_head
  25. Get posts by meta value with date
  26. Change the headers content type with wp_remote_post
  27. Displaying posts with only upcoming dates according their custom field date value
  28. Different custom header image on different page
  29. Why I can’t add a script-code into theme-settings without 403-forbidden?
  30. HTTP Header on specific page is application instead of text
  31. Auto-refresh page every minute?
  32. Displaying custom posts only if custom meta box’s date is not expired
  33. Is it wrong to put header tags inside WordPress help tabs? [closed]
  34. Custom Post Type Events Archive Grouped By Month
  35. Authenticate a user for current request
  36. Remove link around logo
  37. Show post updated date instead of published
  38. Want to make header and footer CMS driven sothat Editors can modify its content from wordpress admin section
  39. Facebook embeds loading the wrong language
  40. Page source contains an http item that makes page insecure; but in php files it’s written as https!
  41. Cleanup Body_Class
  42. Banner in WordPress
  43. Google Tag Manger – no-script Code Not Found
  44. Determine what pages are in my header [closed]
  45. How to remove main domain header title from after sub domain header title
  46. I want to hide header in the static homepage that I am working on [closed]
  47. Remove all WordPress HTTP headers (not in-source embeds)
  48. WordPress 502 | Header Upstream send too big
  49. Creating dynamic header and footer files
  50. Strange 403 header response
  51. 404 or ugly page on IE, but Firefox, Chrome looks perfect
  52. Changing header text from uppercase to normal [closed]
  53. Ordering posts by custom field named “date” in backend
  54. Safe to start a php session on get_header action?
  55. My header not showing up [closed]
  56. How to Access Script Tags in Header
  57. H1 tags for header image?
  58. Where are my js and css links in header?
  59. Why does WordPress allow inserting tags into posts?
  60. How to remove Date from Meta Description on SERP?
  61. Is there a way to get minimal WordPress functions for iframed content?
  62. Sort Posts By Custom Field Date?
  63. Problems accessing stylesheets/scripts loaded in WP header
  64. Rotate images in header based on date
  65. Why does WP load so many files in the head of source code? How do I optimize it?
  66. Trying to set a cookie based on $_POST parameter
  67. How to add some lines to the wp-login.php header via functions.php?
  68. How to Customize Wp Default Title and a prefix
  69. Hook to change HTTP response headers
  70. allowed_http_origins() only works in theme functions.php
  71. Insert stylesheet into WordPress header?
  72. Why are tags from the header showing up on my WordPress site? [closed]
  73. How to register and set http/2 server prefetch for a specific asset?
  74. Header with content
  75. Correct meta of Writing Meta Tags
  76. Problem with adding custom post type meta to header by plugin
  77. WordPress Template not getting my Sub-Header File
  78. How to add social follow button to header? [closed]
  79. Include two headers
  80. Empty header tags [closed]
  81. Insert Facebook button into header [closed]
  82. What is this HTTP_REFERRER “WordPress/4.1.2”
  83. Empty lines in header, how to remove them
  84. Benefits to using CSS for header image instead of html img tag [closed]
  85. Export Header and Footer
  86. Custom headers in WordPress, are there also custom footers?
  87. Point get_header() to different plugin
  88. How do I begin debugging where the description meta tag is set for my categories?
  89. How do I get the Social Media Plugin to show up in my Twenty Eleven child theme’s header?
  90. Inserting iframe right after on header.php
  91. Randomizing Post Links Outside of Loop – No Author or Date
  92. How to add script right after ?
  93. Adding more tabs to horizontal navigation bar
  94. Media attachment date and post date
  95. Code needs wrapper/container to put footer back in, but where?
  96. Dynamic height in custom header image panel
  97. Group Posts By Custom Meta Value: Date
  98. How can I remove or change the tooltip of an icon
  99. Design Header meta on single posts wordpress
  100. Including PHP files in header.php
Categories headers Tags date, headers, post-meta
Image problem – Multisite image upload broken
How to removes all instances of thumbnails displayed in my theme?

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress