In WordPress posts, if you want the default Twenty Fifteen theme to display the updated instead of published date, then there is a simple change in code that must be made. As posted before to make such a change in functionality, the theme files like single.php, content.php etc. should be edited. The edit should replace the PHP code like get_the_date(); with get_the_modified_date();. Locating the exact files and the exact code can be a bit confusing but it is possible. For some themes, functions should be modified which generates the information. We will see this in the Twenty Fifteen WordPress Theme.

While making any changes to themes, it is highly recommended to create a child theme first. This ensures that the changes stay even after the theme is updated. So, for updating Twenty Fifteen’s date displaying code, we must first create a child theme and place it in a folder like twentyfifteen-child. After adding the basic style.css and functions.css to this new folder, it will be ready and can be activated from Appearance > Themes.

In case of Twenty Fifteen, the date is displayed with the help of a function. We’ve searched for it and located it in the file inc/template_tags.php. Notice that there is a folder called inc.

So for the child theme:

It starts from line 47, but the part of the function that we need to look for is in line 64 – 66.

[php firstline=”64″]if ( get_the_time( ‘U’ ) !== get_the_modified_time( ‘U’ ) ) {
$time_string = ‘<time class="entry-date published" datetime="%1$s">%2$s</time><time class="updated" datetime="%3$s">%4$s</time>’;

The function is already configured to display the updated date if the post was modified. But the information is hidden using CSS. We can simply switch the placeholders for published and updated dates.

Simply Switching the Placeholders in The Function

In the function, switch %2 and %4. The section of the code becomes

[php firstline=”64″]if ( get_the_time( ‘U’ ) !== get_the_modified_time( ‘U’ ) ) {
$time_string = ‘<time class="entry-date published" datetime="%1$s">%4$s</time><time class="updated" datetime="%3$s">%2$s</time>’;

We have successfully switched the placeholders set for the updated and published dates. These placeholders were created using a php sprintf function which is seen right below these lines. It is not necessary to understand what this function does. Just know that %2$s is for published date and %4$s is for updated date. Switch them and voila, your posts will display the latest date that the post was updated.

The published date will now be hidden as it falls under the “updated” class. This class is set to display: hidden i.e. it won’t be displayed in the browser but the HTML code will generate it. You can remove the hidden date permanently by removing this part from our updated code

[php light=”true”]<time class="updated" datetime="%3$s">%2$s</time>[/php]

So, the final code becomes:

[php firstline=”64″]if ( get_the_time( ‘U’ ) !== get_the_modified_time( ‘U’ ) ) {
$time_string = ‘<time class="entry-date published" datetime="%1$s">%4$s</time>’;

Another way to achieve it would be to unhide the updated date using CSS but that would just display both of them. Then, we’d have to remove the post published date anyway. So, the steps shows above is quicker and simpler.

Leave a Reply

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