PHP Code to Replace Published Date with Last Modified Date
-
Hi. I’m trying to replace the displayed published date with the last modified date. I’m injecting this script with the WPCode plugin. However, it’s not working at all — no change to the publish date on either pages or posts. Any ideas?
<?php // Hook into the 'the_modified_date' filter for posts add_filter( 'the_modified_date', 'wpse_modified_date', 10, 2 ); // Hook into the 'the_time' filter for pages add_filter( 'the_time', 'wpse_modified_date', 10, 2 ); /** * Replace the published date with the last modified date. * * @param string $the_modified_date The current date string. * @param string $date_format The date format. * @return string The modified date string. */ function wpse_modified_date( $the_modified_date, $date_format ) { // Get the post object $post = get_post(); // Get the last modified date $modified_date = get_the_modified_date( $date_format, $post ); // Replace the published date with the modified date return $modified_date; } ?>
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
The topic ‘PHP Code to Replace Published Date with Last Modified Date’ is closed to new replies.