• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Ani's Webdev Blog

A learning diary of website development

  • Home
  • Demo
    • Ajax Contact Form
  • WordPress
  • Front-end
  • Backend

[WordPress] How to Display Modified Date By Using Hooks (in Newspaper Theme, or Any Theme)

Modified on: December 21, 2020

A modified date will let web visitors know the date that an article was updated, not the publish date (which probably was several years ago!). It provides some trust to the content of the article, also is a plus point for SEO.

I use Newspaper theme in two WordPress websites. It works amazingly as described, only that I could not display the modified date instead of the published date, from the Theme Panel.

I tried the Show Modified Date in the Theme Panel, but it does not work as it should be. Then, I made a child theme and override the time values as this instruction. Still not work.

Finally I can display the modified date to the front end with WordPress hooks. In my opinion, this is quite a clean way to complete the task.

In this post, I will show how to do it. Also, you can apply this method not just in Newspaper theme but also in any other themes, because the principle is the same:

  • First, do a bit of investigation to the theme: How they display the publish date in post settings
  • Second, remove that information from the theme settings, or just set display: none; if theme options do not provide that
  • Third, hook onto the_title, or the_content, and add modified date before / after title or content

Information

Some themes may offer to switch off the date snippet, or to display modified date already in its option (for example in Genesis Theme, users just need to change the shortcode December 21, 2020 to December 21, 2020).

So please check with the theme’s documentation to avoid any unnecessary act. This code implementation should only be performed at the last resource.

Advice

Of course, you can install plugin to do the task (e.g WP Last Modified Info) if you feel comfortable with.

Let me show in more details the third point.

Display modified date by hooking to article’s title or content

WordPress provides users a convenient way to intervene in its basic flow, by using actions and filters (or hooks). That is to say, if you would like to add some information before the article content show, just use the_content. Similarly, you can use the_title to make changes related to the entry title.

So, if you can access your theme child’s functions.php, process as below.

If you cannot access the theme’s functions, install Code Snippets plugin and proceed the code below as a new snippet, and select Only run on site front-end.

Get the modified time

To show the modified date, use get_the_modified_time().

PHP

For Newspaper theme, use the td-module-meta-info and td-post-date classes to get classes styled as the demo.

PHP

For other themes, use whatever class you want, maybe inherit from the theme, or you can create one and style it later.

PHP

Hook it to the_title or the_content

If you would like to display it before the content:

PHP

If you would like to display it after the title:

PHP

Personally, I prefer to attach it before the content, because if it is attached after the title, it will go inside the h1 tag.

Filed Under: Front-end, Wordpress, WordPress Themes Tagged With: php

Recent posts

[WordPress] Let’s Make Plugin E01: A Simple View Count Plugin

[WordPress] Create custom post type programmatically

[WordPress] Open Images in Posts into Lightboxes On Clicks (Without Plugins)

Reader Interactions

You are here: Home / Front-end / [WordPress] How to Display Modified Date By Using Hooks (in Newspaper Theme, or Any Theme)

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Hi! I am a Vietnamese coder living in Oulu, Finland. Currently I am working with PHP, MySQL, HTML, CSS, and JavaScript. This blog is my learning diary, in which I share knowledge from my own experience or research. Hopefully you can find something useful here and don’t hesitate to open a discussion or leave a feedback!

FOLLOW MY BLOG

Thank you for visiting this website! I hope you find something useful here :). Contact me by email: anh@anhkarppinen.com.