{"id":39657,"date":"2013-12-18T15:36:04","date_gmt":"2013-12-18T10:06:04","guid":{"rendered":"https:\/\/www.quickonlinetips.com\/archives\/?p=39657"},"modified":"2020-05-24T11:05:25","modified_gmt":"2020-05-24T05:35:25","slug":"add-updated-date-wordpress","status":"publish","type":"post","link":"https:\/\/www.quickonlinetips.com\/archives\/2013\/12\/add-updated-date-wordpress\/","title":{"rendered":"How to Add Updated Date to Official WordPress Themes"},"content":{"rendered":"<p>It is a good idea to add updated post date and time to your WordPress posts to let search engines know when your post was updated. As search engines have started giving higher search engine rankings to \u00a0recently posted articles or updated content, it is essential to post updated dates.<\/p>\n<h2>Structured Data Errors<\/h2>\n<p>We analysed the new structured data reports in Google webmaster tools and saw thousands of errors on all posts and pages. When we tested the <a href=\"https:\/\/search.google.com\/structured-data\/testing-tool\" target=\"_blank\" rel=\"noopener noreferrer\">rich snippet testing tool,<\/a> there were no errors.<\/p>\n<p><img decoding=\"async\" class=\"alignnone wp-image-39658\" style=\"border: 1px solid black;\" src=\"https:\/\/www.quickonlinetips.com\/archives\/wp-content\/uploads\/structured-data-error.png\" alt=\"structureddataerror\" width=\"487\" height=\"209\" srcset=\"https:\/\/www.quickonlinetips.com\/archives\/wp-content\/uploads\/structured-data-error.png 487w, https:\/\/www.quickonlinetips.com\/archives\/wp-content\/uploads\/structured-data-error-150x64.png 150w, https:\/\/www.quickonlinetips.com\/archives\/wp-content\/uploads\/structured-data-error-300x128.png 300w\" sizes=\"(max-width: 487px) 100vw, 487px\" \/><\/p>\n<p>The errors were caused by missing updated class in the hatom microdata.<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-39659\" style=\"border: 1px solid black;\" src=\"https:\/\/www.quickonlinetips.com\/archives\/wp-content\/uploads\/missing-updated-errors.png\" alt=\"missing updated errors\" width=\"440\" height=\"157\" srcset=\"https:\/\/www.quickonlinetips.com\/archives\/wp-content\/uploads\/missing-updated-errors.png 440w, https:\/\/www.quickonlinetips.com\/archives\/wp-content\/uploads\/missing-updated-errors-150x53.png 150w, https:\/\/www.quickonlinetips.com\/archives\/wp-content\/uploads\/missing-updated-errors-300x107.png 300w\" sizes=\"(max-width: 440px) 100vw, 440px\" \/><\/p>\n<p>If you read the <a href=\"http:\/\/microformats.org\/wiki\/hentry\" target=\"_blank\" rel=\"noopener noreferrer\">hentry<\/a> guidelines, you find that <em>updated<\/em> is a required field (not the <em>published<\/em> date!). In fact only <em>entry-title<\/em> and <em>updated<\/em> are required 2 classes, rest are all optional. So it is a great idea to add updated classes to your post.<\/p>\n<p>If you remember, we had added both the published and updated dates for quite some time, but then Google ignores the updated date. So maybe it is a better idea to only show updated dates.<\/p>\n<h2>Display Updated Date in Twenty Fourteen Theme<\/h2>\n<p>While we discussed how to <a href=\"https:\/\/www.quickonlinetips.com\/archives\/2013\/07\/add-updated-date-markup\/\">add updated date<\/a>\u00a0by direct php code insertion in the post, when I checked my <a title=\"New Default Twenty Fourteen WordPress Theme\" href=\"https:\/\/www.quickonlinetips.com\/archives\/2013\/11\/default-twenty-fourteen-wordpress-theme\/\">Twenty Fourteen WordPress theme<\/a>, it was not so easy to edit it.<\/p>\n<p>Since we use a child theme (which you should always do for <em>any<\/em> theme), we needed to add some code to the <em>functions.php<\/em> file to edit the post meta information.<\/p>\n<p>If you check the <em>content.php<\/em> file in your theme, the particular code <strong><em>twentyfourteen_posted_on<\/em><\/strong>\u00a0 outputs the post meta, and is located in the <a href=\"http:\/\/develop.svn.wordpress.org\/branches\/3.8\/src\/wp-content\/themes\/twentyfourteen\/inc\/template-tags.php\" target=\"_blank\" rel=\"noopener noreferrer\"><em>template-tags.php<\/em><\/a>. The detailed code looks like this<\/p>\n<pre><code>if ( ! function_exists( 'twentyfourteen_posted_on' ) ) :\r\n\/**\r\n* Print HTML with meta information for the current post-date\/time and author.\r\n*\r\n* @since Twenty Fourteen 1.0\r\n*\r\n* @return void\r\n*\/\r\nfunction twentyfourteen_posted_on() {\r\nif ( is_sticky() &amp;&amp; is_home() &amp;&amp; ! is_paged() ) {\r\necho '&lt;span class=\"featured-post\"&gt;' . __( 'Sticky', 'twentyfourteen' ) . '&lt;\/span&gt;';\r\n}\r\n\r\n\/\/ Set up and print post meta information.\r\nprintf( '&lt;span class=\"entry-date\"&gt;&lt;a href=\"%1$s\" rel=\"bookmark\"&gt;&lt;time class=\"entry-date\"\u00a0datetime=\"%2$s\"&gt;%3$s&lt;\/time&gt;&lt;\/a&gt;&lt;\/span&gt; &lt;span\u00a0class=\"byline\"&gt;&lt;span class=\"author vcard\"&gt;&lt;a class=\"url fn n\"\u00a0href=\"%4$s\" rel=\"author\"&gt;%5$s&lt;\/a&gt;&lt;\/span&gt;&lt;\/span&gt;',\r\nesc_url( get_permalink() ),\r\nesc_attr( get_the_date( 'c' ) ),\r\nesc_html( get_the_date() ),\r\nesc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),\r\nget_the_author()\r\n);\r\n}\r\nendif;<\/code><\/pre>\n<p>Here are the changes we will make to this code and then add to the child themes <em>functions.php<\/em> file. Remember to keep a back up of this file as any error will need the original to be replaced via FTP.<\/p>\n<ol>\n<li><strong>Show Updated Date<\/strong> &#8211;\u00a0So we will edit this to replace the <a href=\"https:\/\/developer.wordpress.org\/reference\/functions\/get_the_date\/\" target=\"_blank\" rel=\"noopener noreferrer\">get_the_date<\/a> with <a href=\"https:\/\/codex.wordpress.org\/Function_Reference\/get_the_modified_date\" target=\"_blank\" rel=\"noopener noreferrer\">get_the_modified_date<\/a> code. This will serve the updated date instead of the published date.<\/li>\n<li><strong>Updated Class<\/strong> &#8211; Add the <em>updated<\/em> class to the date so that the hentry microdata becomes valid and the structured data errors are gone.<\/li>\n<li><strong>Show Updated Text<\/strong> &#8211; \u00a0it is a good idea to show updated text besides the date to let readers know that this is the updated date and not the original post published date. You do not want people to find 5 year old comments in a post which shows a month old date.<\/li>\n<\/ol>\n<p>So here is the same code we have modified *changes seen in bold and underline). You can check this live on our site now.<\/p>\n<pre><code>if ( ! function_exists( 'twentyfourteen_posted_on' ) ) :\r\n\/**\r\n* Print HTML with meta information for the current post-date\/time and author.\r\n*\r\n* @since Twenty Fourteen 1.0\r\n*\r\n* @return void\r\n*\/\r\nfunction twentyfourteen_posted_on() {\r\nif ( is_sticky() &amp;&amp; is_home() &amp;&amp; ! is_paged() ) {\r\necho '&lt;span class=\"featured-post\"&gt;' . __( 'Sticky', 'twentyfourteen' ) . '&lt;\/span&gt;';\r\n}\r\n\r\n\/\/ Set up and print post meta information.\r\nprintf( '<span style=\"text-decoration: underline;\"><strong>UPDATED<\/strong><\/span> &lt;span class=\"entry-date <span style=\"text-decoration: underline;\"><strong>updated<\/strong><\/span>\"&gt;&lt;a href=\"%1$s\" rel=\"bookmark\"&gt;&lt;time class=\"entry-date <span style=\"text-decoration: underline;\"><strong>updated<\/strong><\/span>\"\u00a0datetime=\"%2$s\"&gt;%3$s&lt;\/time&gt;&lt;\/a&gt;&lt;\/span&gt; &lt;span\u00a0class=\"byline\"&gt;&lt;span class=\"author vcard\"&gt;&lt;a class=\"url fn n\"\u00a0href=\"%4$s\" rel=\"author\"&gt;%5$s&lt;\/a&gt;&lt;\/span&gt;&lt;\/span&gt;',\r\nesc_url( get_permalink() ),\r\nesc_attr( <span style=\"text-decoration: underline;\"><strong>get_the_modified_date<\/strong><\/span>( 'c' ) ),\r\nesc_html( <span style=\"text-decoration: underline;\"><strong>get_the_modified_date<\/strong><\/span>() ),\r\nesc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),\r\nget_the_author()\r\n);\r\n}\r\nendif;<\/code><\/pre>\n<p><em><span style=\"color: #ff0000;\"><strong>NOTE<\/strong><\/span>: Please do these changes at your own risk. We take no responsibility of how this will affect your site rankings \u00a0in search engine results.<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>It is a good idea to add updated post date and time to your WordPress posts to let search engines&#8230;<\/p>\n","protected":false},"author":4,"featured_media":39658,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","footnotes":""},"categories":[6,41],"tags":[49,17],"class_list":["post-39657","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blogging","category-search-engine-optimization","tag-tutorials","tag-wordpress"],"_links":{"self":[{"href":"https:\/\/www.quickonlinetips.com\/archives\/wp-json\/wp\/v2\/posts\/39657","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.quickonlinetips.com\/archives\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.quickonlinetips.com\/archives\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.quickonlinetips.com\/archives\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.quickonlinetips.com\/archives\/wp-json\/wp\/v2\/comments?post=39657"}],"version-history":[{"count":0,"href":"https:\/\/www.quickonlinetips.com\/archives\/wp-json\/wp\/v2\/posts\/39657\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.quickonlinetips.com\/archives\/wp-json\/wp\/v2\/media\/39658"}],"wp:attachment":[{"href":"https:\/\/www.quickonlinetips.com\/archives\/wp-json\/wp\/v2\/media?parent=39657"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.quickonlinetips.com\/archives\/wp-json\/wp\/v2\/categories?post=39657"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.quickonlinetips.com\/archives\/wp-json\/wp\/v2\/tags?post=39657"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}