0

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".

1
  • You can achieve it by using filter. Check my answer bellow Feb 14, 2021 at 9:04

1 Answer 1

0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.