{"id":14732,"date":"2023-05-23T15:00:58","date_gmt":"2023-05-23T13:00:58","guid":{"rendered":"https:\/\/qodeinteractive.com\/magazine\/?p=14732"},"modified":"2023-05-23T21:50:41","modified_gmt":"2023-05-23T19:50:41","slug":"last-updated-date-in-wordpress","status":"publish","type":"post","link":"https:\/\/qodeinteractive.com\/magazine\/last-updated-date-in-wordpress\/","title":{"rendered":"How to Add the &#8220;Last Updated&#8221; Date in WordPress"},"content":{"rendered":"<div class=\"wpb-content-wrapper\"><p>[vc_row][vc_column][vc_column_text]If you\u2019re a blogger, an online news publisher, or if you own any other type of article-based website, it\u2019s important to let your visitors know that the articles you post are fresh and up to date. Even though WordPress doesn\u2019t come with this feature right out of the box, there is still an easy way to add the \u201clast updated\u201d date to your WordPress posts.<br \/>\n[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]Today, <strong>we\u2019re going to share some simple steps that will allow you to display the date when your article was last updated<\/strong> and make things more convenient for your website visitors:[\/vc_column_text][vc_empty_space height=&#8221;22px&#8221;]<ul class=\"qodef-unordered-list-item qodef-toc\">\n    <li>\n\t        <div class=\"qodef-ul-title-holder\">\n            <span class=\"qodef-ul-title-content\"><a href=\"#when-to-add-last-updated\">When to Consider Adding Last Updated Date to Your WordPress Posts<\/a><\/span>        <\/div>\n            <\/li>\n<\/ul>[vc_empty_space height=&#8221;5px&#8221;]<ul class=\"qodef-unordered-list-item qodef-toc\">\n    <li>\n\t        <div class=\"qodef-ul-title-holder\">\n            <span class=\"qodef-ul-title-content\"><a href=\"#displaying-the-last-updated-date-using-functions-php\">Displaying the Last Updated Date Using Functions.php<\/a><\/span>        <\/div>\n            <\/li>\n<\/ul>[vc_empty_space height=&#8221;5px&#8221;]<ul class=\"qodef-unordered-list-item qodef-toc\">\n    <li>\n\t        <div class=\"qodef-ul-title-holder\">\n            <span class=\"qodef-ul-title-content\"><a href=\"#displaying-the-last-updated-date-using-theme-templates\">Displaying the Last Updated Date Using Theme Templates<\/a><\/span>        <\/div>\n            <\/li>\n<\/ul>[vc_empty_space height=&#8221;68px&#8221;][\/vc_column][\/vc_row][vc_row][vc_column][vc_column_text]<\/p>\n<h2 class=\"qodef-h4\"><a id=\"when-to-add-last-updated\"><\/a>When to Consider Adding Last Updated Date to Your WordPress Posts<\/h2>\n<p>[\/vc_column_text][vc_column_text]It\u2019s common for most <a href=\"https:\/\/qodeinteractive.com\/themes-list\/\">WordPress themes<\/a> to display the date of publishing for each article, which is also what works for most websites. That being said, some websites post content that gets updated regularly, for one reason or another.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]For example, in the case of a news website, there\u2019s a high chance an old story will need to be updated at some point. This can be an update that contains the latest information about any recent happenings related to the topic at hand that have occurred in the meantime, i.e. after the article has been posted. Also, various online tutorials, product and service reviews, tour guide articles, etc. can all contain time-sensitive information. The relevance and freshness of these types of content can depend on different factors, such as the pricing, changes in product features, terms of use, and so on. As such, they should be updated regularly. And if you want your users to be aware of those updates, showing the last updated date on your posts can be a good practice.<br \/>\n[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]Also, for many users, articles that are more than two years old will usually be dismissed as no longer relevant, even if they somehow appear at the top of Google search results.<br \/>\n[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]The fact of the matter is, <strong>the older your post is, the less are the chances it\u2019ll get clicked on<\/strong>. Google takes this factor into account when it comes to its ranking algorithm as well, and also displays the date a post was published (or updated) in SERPs.[\/vc_column_text][vc_empty_space height=&#8221;50px&#8221;]<div class=\"qodef-single-image-holder   qodef-has-border \">\n    <div class=\"qodef-si-inner\" >\n                                    <img loading=\"lazy\" decoding=\"async\" width=\"700\" height=\"374\" src=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/10\/Publishing-Date.jpg\" class=\"attachment-full size-full\" alt=\"Publishing Date\" srcset=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/10\/Publishing-Date.jpg 700w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/10\/Publishing-Date-300x160.jpg 300w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/10\/Publishing-Date-620x331.jpg 620w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/>                        <\/div>\n<\/div>[vc_empty_space height=&#8221;38px&#8221;][vc_column_text]That being said, there are articles written years ago that have the evergreen type of content still relevant to this day. Still, <strong>many websites make sure to update these types of articles regularly<\/strong> so as not to waste the potential these articles have. This way, <strong>they\u2019re indicating to the users that the content they\u2019re interested in is still fresh<\/strong>. If you\u2019re also among those who want to prevent their high-quality posts from losing much-needed views (and quite frankly, why wouldn\u2019t you be?) we advise you to do the same.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]If you have content that you intend updating but still want to make sure your readers know it\u2019s not exactly fresh, there\u2019s a neat workaround you can use. <a href=\"https:\/\/qodeinteractive.com\/magazine\/wordpress-old-post-notification\">Displaying an \u201cOld Post\u201d notification<\/a> above your post will let your visitors know they need to take the content with a grain of salt. It\u2019s easy to do with the help of a handy little plugin, and it will get you a long way in terms of UX and trust. It shows that you\u2019re regularly revisiting your content making sure everything is in order, and it also helps with accountability in case your post contains info that is no longer valid.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]But that\u2019s a subject we tackled in a separate article, linked above, so right now let\u2019s get back to our topic here, which is adding the last updated date to your posts.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]While WordPress does not come with the option to display the last modified date of your post by default, luckily, there\u2019s always an option to do it manually. All you need to do is <strong>insert a few lines of code in the files of the WordPress theme you\u2019re using<\/strong> \u2013 and this time around, we\u2019re going to show you how.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]Without further ado, here are some easy instructions you can follow to display the \u201cLast Updated\u201d date in WordPress. You can either achieve this by <strong>editing the theme\u2019s functions.php file<\/strong> or<strong> inserting a code snippet into one of your theme\u2019s template files<\/strong>.[\/vc_column_text][vc_empty_space height=&#8221;80px&#8221;][vc_widget_sidebar sidebar_id=&#8221;new-top-picks-banner&#8221;][vc_empty_space height=&#8221;81px&#8221;][\/vc_column][\/vc_row][vc_row][vc_column][vc_column_text]<\/p>\n<h2 class=\"qodef-h4\"><a id=\"displaying-the-last-updated-date-using-functions-php\"><\/a>Displaying the Last Updated Date Using Functions.php<\/h2>\n<p>[\/vc_column_text][vc_column_text]To add the last updated date before your content, you need to add a line of code into your theme\u2019s <strong>functions.php<\/strong> file.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]Go to <em>Appearance &gt;&gt; Theme Editor<\/em> in your admin dashboard and find your functions.php file in the <em>Theme Files<\/em> list.[\/vc_column_text][vc_empty_space height=&#8221;50px&#8221;]<div class=\"qodef-single-image-holder   qodef-has-border \">\n    <div class=\"qodef-si-inner\" >\n                                    <img loading=\"lazy\" decoding=\"async\" width=\"700\" height=\"374\" src=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/10\/Theme-Functions.jpg\" class=\"attachment-full size-full\" alt=\"Theme Functions\" srcset=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/10\/Theme-Functions.jpg 700w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/10\/Theme-Functions-300x160.jpg 300w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/10\/Theme-Functions-620x331.jpg 620w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/>                        <\/div>\n<\/div>[vc_empty_space height=&#8221;38px&#8221;][vc_column_text]Then, insert the following code at the very end of the file:[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">function my_last_updated_date( $content ) {\r\n$u_time = get_the_time('U');\r\n$u_modified_time = get_the_modified_time('U');\r\nif ($u_modified_time &gt;= $u_time + 86400) {\r\n$updated_date = get_the_modified_time('F jS, Y');\r\n$updated_time = get_the_modified_time('h:i a');\r\n$custom_content .= '&lt;p class=\"last-updated entry-meta\"&gt;Last updated on '. $updated_date . ' at '. $updated_time .'&lt;\/p&gt;';\r\n}\r\n$custom_content .= $content;\r\nreturn $custom_content;\r\n}\r\nadd_filter( 'the_content', 'my_last_updated_date' );<\/pre>\n<p>[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]The code works by <strong>checking whether there\u2019s a difference between a published date of the post in question and its last modified date<\/strong>. If these two dates are different, then the last modified date will be displayed.[\/vc_column_text][vc_empty_space height=&#8221;50px&#8221;]<div class=\"qodef-single-image-holder   qodef-has-border \">\n    <div class=\"qodef-si-inner\" >\n                                    <img loading=\"lazy\" decoding=\"async\" width=\"700\" height=\"374\" src=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/10\/Theme-Functions-Code.jpg\" class=\"attachment-full size-full\" alt=\"Theme Functions Code\" srcset=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/10\/Theme-Functions-Code.jpg 700w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/10\/Theme-Functions-Code-300x160.jpg 300w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/10\/Theme-Functions-Code-620x331.jpg 620w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/>                        <\/div>\n<\/div>[vc_empty_space height=&#8221;38px&#8221;][vc_column_text]Once you insert your code, make sure to hit the <em>Update File<\/em> button.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]If you want, you can even add some custom CSS to your theme\u2019s stylesheet (or by going to <em>Appearance &gt;&gt; Customize<\/em> and using the <em>Additional CSS<\/em> option). For example, you can use this code as your base:[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">.last-updated {\r\nfont-size: small;\r\ntext-transform: uppercase;\r\nbackground-color: #fffdd4;\r\n}<\/pre>\n<p>[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]Here\u2019s what our final result looks like:[\/vc_column_text][vc_empty_space height=&#8221;50px&#8221;]<div class=\"qodef-single-image-holder   qodef-has-border \">\n    <div class=\"qodef-si-inner\" >\n                                    <img loading=\"lazy\" decoding=\"async\" width=\"700\" height=\"374\" src=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/10\/Last-Updated-Date.jpg\" class=\"attachment-full size-full\" alt=\"Last Updated Date\" srcset=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/10\/Last-Updated-Date.jpg 700w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/10\/Last-Updated-Date-300x160.jpg 300w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/10\/Last-Updated-Date-620x331.jpg 620w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/>                        <\/div>\n<\/div>[vc_empty_space height=&#8221;78px&#8221;][\/vc_column][\/vc_row][vc_row][vc_column][vc_column_text]<\/p>\n<h2 class=\"qodef-h4\"><a id=\"displaying-the-last-updated-date-using-theme-templates\"><\/a>Displaying the Last Updated Date Using Theme Templates<\/h2>\n<p>[\/vc_column_text][vc_column_text]Another way to do this is to<strong> use the specific template file of your theme<\/strong>. Most themes use different templates for the purpose of displaying posts, like single.php, index.php, archive.php, and so on.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]What you need to do is find the code within the file that displays your date and time, and then either replace the already-existing code with the one we will share with you below, or insert it right underneath the theme\u2019s \u201cdate and time\u201d code. The former will only display the last modified date of your post (without the original published date), while the latter will allow you to have both dates displayed above your content.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]We used the Twenty Seventeen theme for this purpose. The date and time code for this theme is located in the <strong>template-tags.php<\/strong> file.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]What we did was find the function called \u2018twentyseventeen_time_link\u2019 and placed the following right below the \u2018get_the_time\u2019 line of code:[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">$u_time = get_the_time('U'); \r\n$u_modified_time = get_the_modified_time('U'); \r\nif ($u_modified_time &gt;= $u_time + 86400) { \r\necho \"&lt;p class=\"last-updated entry-meta\"&gt;Last modified on \"; \r\nthe_modified_time('F jS, Y'); \r\necho \" at \"; \r\nthe_modified_time(); \r\necho \"&lt;\/p&gt; \"; }<\/pre>\n<p>[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]You can use the same code within your own theme\u2019s template file. [\/vc_column_text][vc_empty_space height=&#8221;50px&#8221;]<div class=\"qodef-single-image-holder   qodef-has-border \">\n    <div class=\"qodef-si-inner\" >\n                                    <img loading=\"lazy\" decoding=\"async\" width=\"700\" height=\"374\" src=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/10\/Displaying-the-Last-Updated-Date-Using-Theme-Templates.jpg\" class=\"attachment-full size-full\" alt=\"Displaying the Last Updated Date Using Theme Templates\" srcset=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/10\/Displaying-the-Last-Updated-Date-Using-Theme-Templates.jpg 700w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/10\/Displaying-the-Last-Updated-Date-Using-Theme-Templates-300x160.jpg 300w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/10\/Displaying-the-Last-Updated-Date-Using-Theme-Templates-620x331.jpg 620w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/>                        <\/div>\n<\/div>[vc_empty_space height=&#8221;38px&#8221;][vc_column_text]Just hit the <em>Update File<\/em> button when you\u2019re done, and that\u2019s it \u2013 your post will now display the date when your post was last modified.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]And here&#8217;s what it looks like on our end:[\/vc_column_text][vc_empty_space height=&#8221;50px&#8221;]<div class=\"qodef-single-image-holder   qodef-has-border \">\n    <div class=\"qodef-si-inner\" >\n                                    <img loading=\"lazy\" decoding=\"async\" width=\"700\" height=\"374\" src=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/10\/Last-Modified-Date.jpg\" class=\"attachment-full size-full\" alt=\"Last Modified Date\" srcset=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/10\/Last-Modified-Date.jpg 700w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/10\/Last-Modified-Date-300x160.jpg 300w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/10\/Last-Modified-Date-620x331.jpg 620w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/>                        <\/div>\n<\/div>[vc_empty_space height=&#8221;78px&#8221;][\/vc_column][\/vc_row][vc_row][vc_column][vc_column_text]<\/p>\n<h2 class=\"qodef-h4\">Wrapping Up<\/h2>\n<p>[\/vc_column_text][vc_column_text]If you\u2019re a website or blog owner that strives to update their content regularly, then you might want to consider adding the \u201cLast Updated\u201d feature to your WordPress posts. This practice is particularly convenient as it allows you to show your visitors that your content is always fresh and relevant. As you can see from our tutorial, the method that allows you to insert the code directly into your theme\u2019s functions.php is relatively simple even for beginners and does the job quite well. Alternatively, you can also easily display your post\u2019s last modified date by adding the code into one of your theme\u2019s template files. Finally, don\u2019t forget that you can also display a notification that says your post is relatively old, indicating you\u2019re planning to update it as soon as possible.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]By employing these easy techniques, you can help boost the trust your readers have in you and your blog or website and establish it as a reliable and accurate source of content.<br \/>\n[\/vc_column_text][\/vc_column][\/vc_row]<\/p>\n<\/div>","protected":false},"excerpt":{"rendered":"<p>Here are some simple steps you can follow to add the \u201clast updated\u201d date of your WordPress posts and make things more convenient for your website visitors.<\/p>\n","protected":false},"author":2,"featured_media":14975,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[21,4,13],"class_list":["post-14732","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","tag-php","tag-tips","tag-wordpress"],"_links":{"self":[{"href":"https:\/\/qodeinteractive.com\/magazine\/wp-json\/wp\/v2\/posts\/14732","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/qodeinteractive.com\/magazine\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/qodeinteractive.com\/magazine\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/qodeinteractive.com\/magazine\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/qodeinteractive.com\/magazine\/wp-json\/wp\/v2\/comments?post=14732"}],"version-history":[{"count":0,"href":"https:\/\/qodeinteractive.com\/magazine\/wp-json\/wp\/v2\/posts\/14732\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/qodeinteractive.com\/magazine\/wp-json\/wp\/v2\/media\/14975"}],"wp:attachment":[{"href":"https:\/\/qodeinteractive.com\/magazine\/wp-json\/wp\/v2\/media?parent=14732"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/qodeinteractive.com\/magazine\/wp-json\/wp\/v2\/categories?post=14732"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/qodeinteractive.com\/magazine\/wp-json\/wp\/v2\/tags?post=14732"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}