Latest theme for WordPress called TwentyThirteen is nice, but still doesn’t have Last Modified date in post meta. “Last Modified” date is required by Google to get an enhanced listing in search results. This requirements can be tested in Structured Data Testing Tool.
So each site post must have 2 classes named date updated
in the code and to show a date. Previously many people just added class updated
to a regular date in a template loop code. This is the simplest solution, but doesn’t show the real update date. This time I just wanted to implement this from functions.php
of my child theme and to have a real date of update. Even hidden with CSS it can provide a valuable hint sometimes.
I’ve copied the date function from Twentythirteen’s functions.php
and added last modified date code in.
/* add updated date of post for google scheme */ function twentythirteen_entry_date( $echo = true ) { if ( has_post_format( array( 'chat', 'status' ) ) ) $format_prefix = _x( '%1$s on %2$s', '1: post format name. 2: date', 'twentythirteen' ); else $format_prefix = '%2$s'; $date = sprintf( '<span class="date"><a href="%1$s" title="%2$s" rel="bookmark"><time class="entry-date" datetime="%3$s">%4$s</time></a></span><span class="date updated"><time datetime="%5$s">%6$s</time></span>', esc_url( get_permalink() ), esc_attr( sprintf( __( 'Permalink to %s', 'twentythirteen' ), the_title_attribute( 'echo=0' ) ) ), esc_attr( get_the_date( 'c' ) ), esc_html( sprintf( $format_prefix, get_post_format_string( get_post_format() ), get_the_date() ) ), esc_attr( get_the_modified_date( 'c' ) ), esc_html( sprintf( $format_prefix, get_post_format_string( get_post_format() ), get_the_modified_date() ) ) ); if ( $echo ) echo $date; return $date; }
This works for me, just made the modified date hidden with css.
Thanks Iggy for this helpful article. I do not know much about php coding. Can you tell how the code would look like if you do not want to hide but show “Last modified”?