Last active
November 19, 2018 18:11
-
-
Save dannydover/18ec8212ab33a7c896fba15fa6457ab8 to your computer and use it in GitHub Desktop.
Replace Published date with Updated date within Wordpress (Divi Specific)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /* Show last updated date rather than first posted date */ | |
| function show_last_modified_date_blog( $the_date, $format ) { | |
| if ( 'guides' === get_post_type() && 'U' !== $format ) { // Make sure the Unix timestamp is not being requested. | |
| $the_time = get_post_time( 'His' ); | |
| $the_modified = get_post_modified_time( 'His' ); | |
| $last_modified = sprintf( __( 'Last Updated %s', 'Divi' ), esc_html( get_post_modified_time( 'M j, Y' ) ) ); | |
| $published = sprintf( __( 'Published on %s', 'Divi' ), esc_html( get_post_time( 'M j, Y' ) ) ); | |
| $the_date = $the_modified !== $the_time ? $last_modified : $published; | |
| } | |
| return $the_date; // A filter must always return a value. | |
| } | |
| add_filter( 'get_the_date', 'show_last_modified_date_blog', 10, 2 ); | |
| add_filter( 'get_the_time', 'show_last_modified_date_blog', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment