WordPress

Display the Last Updated Date in WooThemes Canvas

woothemes logo smallAs a blogger if you are regularly updating your blog posts to keep them fresh, it also becomes important to display the last updated date in the posts instead of the original publication date. This ensures the readers that the content is recently updated and hence is still valid. Besides this, Search engines such as Google also show this date in the search snippet. Now because you’re reading this, you’d be already familiar with the fact why the Modified Date should be shown, so let’s just skip to how to show it in WooThemes Canvas.last updated

Creating a Shortcode to fetch the Last Modified Date

Note: I’d recommend you to create a child theme of Canvas (if you are are using it directly) as these changes will be lost whenever you update your theme.

WooThemes Canvas makes use of the very powerful WooFramework and hence a lot of the work of the theme is handled by shortcodes which are created in the /includes/theme-shortcodes.php file. We will just amend the already created shortcode post_date to create a new function post_moddate which will use the WordPress’s modified _time function. To add this shortcode, insert the following code to the end of your /includes/theme-shortcodes.php just before the closing php tag (child theme is recommended).

You can then call this shortcode anywhere in your content and the modified date will be displayed there. But that is not a feasible option. The following part shows how to replace the default post published date of canvas with the modified date.

Replacing Published Time with Last Modified Time

In order to replace the default Published Time with the Lost Modified Time, we need to edit the /includes/theme-actions.php file (again, child theme recommended) and further edit the woo_post_meta function to replace the post_date shortcode with our earlier created post_moddate shortcode. The basic implementation will be to simply replace post_date at line 1730 with post_moddate. Else if you want to make it look a little better, just like it is done at TechMesto, replace the entire function code with the following code (i.e. replace from line 1712 till 1734)

Save the file when done. Your posts pages will now start showing the last updated date instead of the date when the post was first published.

In case a post is never updated after it is published, the post publication date will be the last modified date as well.

3 Comments

Click here to post a comment

Email me when somebody replies to my comment.

  • Your code samples have gone missing and I’m far too ignorant to recreate them. Hopefully the friend I meet for coffee on the weekend is a bit more code-savvy. Good clues here, though.

    • Sorry about that. What happened was that the code snippets were hosted on Pastebin and worked fine till we switched the blog to HTTPS. Non-HTTPS elements are blocked by browsers when you visit a HTTPS page. So that made them missing.
      I’ve recreated the code on Gist and should be visible in the post. However, because the theme has gone multiple updates after that, line numbers might have changed.

  • Thanks a lot for this. I want to make the last updated date visible because I regularly update my posts. Thanks a lot man!

Subscribe for email updates!

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 4,246 other subscribers