InfoHeap
Tech
Navigation
  • Home
  • Tutorials
    • CSS tutorials & examples
    • CSS properties
    • Javascript cookbook
    • Linux/Unix Command Line
    • Mac
    • PHP
      • PHP functions online
      • PHP regex
    • WordPress
  • Online Tools
    • Text utilities
    • Online Lint Tools
search

Wordpress customization tutorials

  • Handle pagination in wordpress custom php code
  • How to and why disable wordpress cron
  • How to customize wordpress image alt tag
  • How to display date in wordpress pages
  • How to display wordpress page list with specific custom field value
  • How to display wordpress top level pages
  • How to hide a post from home and RSS feed in wordpress
  • How to include bootstrap javascript and css in wordpress post
  • How to include wordpress pages in archives
  • How to override priority and change frequency in Yoast xml sitemap
  • How to remove xmlrpc from wordpress headers
  • How to setup wordpress custom query params with pretty url format
  • How to show wordpress pages on front page with skip_home custom field
  • How to use google custom search for wordpress site
  • How to write custom php in wordpress
  • No frills social share links for Wordpress sites
  • Using Wordpress custom field for displaying code
  • Wordpress - add content filter after shortcode execution
  • Wordpress - customize category and tag links
  • Wordpress - customize facebook plugin opengraph meta tags
  • Wordpress - customize posts per page for tag, category and date archive pages
  • Wordpress - exclude specific posts from archive pages
  • Wordpress - get posts/pages with missing meta key
  • Wordpress - how to add filter to description meta tag
  • Wordpress - how to create custom tag cloud
  • Wordpress - how to exclude specific tag posts from a tag archive page
  • Wordpress - write custom php log to separate file
  • Wordpress how to check if a post is being viewed by admin
 
  • Home
  • > Tutorials
  • > Wordpress
  • > Wordpress customization

How to display date in wordpress pages

By admin | Last updated on Mar 20, 2016

The default Twenty Twelve theme which comes with wordpress and many other themes display creation date in wordpress posts but do not display any date (creation of modified) in wordpress pages. For many pages like “about us”, “contact us”, etc. displaying date is not relevant. But sometimes we want to display date in pages.

When would one want to display date in wordpess pages

Here are some cases where displaying date may be relevant.

  1. Pages like some online tools/utilities, tutorials, etc. may be more useful with modification date (date page was last edited on).
  2. Some content you may not want to put in RSS. The one easy option is to create these as pages instead of posts. And then it may be useful for users to have a modification date on some of these pages.

How to display modification date

In case you want to display modification date only on certain wordpress pages, you can do it using various approaches. Here are some of them:

  1. Define a custom field and set it of for pages where you want to display modification date.
  2. Use some url match approach. e.g. you may want to display modification date for all users beginning with /foo/. You can use $_SERVER[‘REQUEST_URI’] to get access to the url. Here is how the php code will look like:
    if (preg_match('#^/foo/#i', $_SERVER["REQUEST_URI"])) {
      // display date logic...
    }

For this article we’ll use custom field approach (with custom field name showModifiedDate). Now look for the page template in your theme. Assuming you have a separate template for page in your theme, one approach is define a shortcode for displaying modification date. Here is wordpress plugin pseudocode for it:

function my_entry_published_shortcode( $attr ) {
  global $post;
  if (!is_page()) {
    return "";
  }
  $show_modified_date_value = get_post_meta($post->ID, 'showModifiedDate', true);
  if (empty($show_modified_date_value) || !in_array($show_modified_date_value, array('true', '1'))) {
    return "";
  }
  $date = sprintf( '<time class="entry-date" datetime="%1$s">%2$s</time>',
      esc_attr( get_the_date( 'c' ) ),
      esc_html( get_the_date() )
  );
  return $date;  
}
add_shortcode( 'entry-modified', 'my_entry_published_shortcode' );

Now you an add short code [modified-date] to the appropriate place in the template. Modify the code appropriately if you want to add some text around it. You may want to take care of localization also in that case.

Suggested posts:

  1. How to setup MailChimp Rss email campaign
  2. How to hide a post from home and RSS feed in wordpress
  3. How to clear Chrome HTTP 301 redirect cache
  4. Fetch wordpress rss feed as FeedBurner user agent on command line
  5. Vim – how to go back to last edited line/context
  6. How to use google custom search for wordpress site
  7. Svn – how to edit log message for a committed change
  8. How to setup wordpress custom query params with pretty url format
Share this article: share on facebook share on linkedin tweet this submit to reddit
Posted in Tutorials | Tagged Tutorials, Wordpress, Wordpress customization
  • Browse content
  • Article Topics
  • Article archives
  • Contact Us
Popular Topics: Android Development | AngularJS | Apache | AWS and EC2 | Bash shell scripting | Chrome developer tools | Company results | CSS | CSS cookbook | CSS properties | CSS Pseudo Classes | CSS selectors | CSS3 | CSS3 flexbox | Devops | Git | HTML | HTML5 | Java | Javascript | Javascript cookbook | Javascript DOM | jQuery | Kubernetes | Linux | Linux/Unix Command Line | Mac | Mac Command Line | Mysql | Networking | Node.js | Online Tools | PHP | PHP cookbook | PHP Regex | Python | Python array | Python cookbook | SEO | Site Performance | SSH | Ubuntu Linux | Web Development | Webmaster | Wordpress | Wordpress customization | Wordpress How To | Wordpress Mysql Queries | InfoHeap Money

Copyright © 2025 InfoHeap.

Powered by WordPress