The date format looks like this “$ datef = _x ('F j, Y @ H: i: s', 'revision date format');” but I want it to be like this “$ datef = _x ('Y-m-d @ H: i: s', 'revision date format');“. I don’t want to modify the core of wordpress, is there a way to do it with a hook?
This is in wp/wp-includes/post-template.php, the function is called “wp_post_revision_title_expanded“.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
You can filter the output like bellow:
<?php
/**
* @param $revision_date_author
* @param $revision
* @param $link
* @return mixed
*/
function filter_wp_post_revision_title_expanded( $revision_date_author, $revision, $link ) {
$revision = get_post( $revision );
if ( ! $revision ) {
return $revision;
}
if ( ! in_array( $revision->post_type, array( 'post', 'page', 'revision' ), true ) ) {
return false;
}
$author = get_the_author_meta( 'display_name', $revision->post_author );
//You can change format Here
$datef = _x( 'F j, Y @ H:i:s', 'revision date format' );
$gravatar = get_avatar( $revision->post_author, 24 );
$date = date_i18n( $datef, strtotime( $revision->post_modified ) );
$edit_link = get_edit_post_link( $revision->ID );
if ( $link && current_user_can( 'edit_post', $revision->ID ) && $edit_link ) {
$date = "<a href='$edit_link'>$date</a>";
}
$revision_date_author = sprintf(
/* translators: Post revision title. 1: Author avatar, 2: Author name, 3: Time ago, 4: Date. */
__( '%1$s %2$s, %3$s ago (%4$s)' ),
$gravatar,
$author,
human_time_diff( strtotime( $revision->post_modified_gmt ) ),
$date
);
return $revision_date_author;
};
// Finally add the filter
add_filter( 'wp_post_revision_title_expanded', 'filter_wp_post_revision_title_expanded', 10, 3 );
Most of the code used in this example are taken from actual wp_post_revision_title_expanded function. read more
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0