Skip to main content
Corrected error that printed out the date instead of returning it later.
Source Link
mor7ifer
  • 8.6k
  • 2
  • 19
  • 32

A late addition, but the following snippet can be modified to use most functions outside of the loop:

/**
 * Returns a post's modified date, formatted according to $format.
 * @uses the_modified_time()
 *
 * @param int $post_id Post ID.
 * @param string $format Date format Default: "F j, Y".
 */
function wpse95769_modified_date_by_id( $post_id = 0, $format = "F j, Y" ){
    global $post;
    $post = &get_post( $post_id );
    setup_postdata( $post );

    $modified_time = get_the_modified_time( $format );

    wp_reset_postdata( $post );

    return $modified_time;
}

A late addition, but the following snippet can be modified to use most functions outside of the loop:

/**
 * Returns a post's modified date, formatted according to $format.
 * @uses the_modified_time()
 *
 * @param int $post_id Post ID.
 * @param string $format Date format Default: "F j, Y".
 */
function wpse95769_modified_date_by_id($post_id = 0, $format = "F j, Y"){
    global $post;
    $post = &get_post($post_id);
    setup_postdata($post);

    $modified_time = get_the_modified_time($format);

    wp_reset_postdata($post);

    return $modified_time;
}

A late addition, but the following snippet can be modified to use most functions outside of the loop:

/**
 * Returns a post's modified date, formatted according to $format.
 * @uses the_modified_time()
 *
 * @param int $post_id Post ID.
 * @param string $format Date format Default: "F j, Y".
 */
function wpse95769_modified_date_by_id( $post_id = 0, $format = "F j, Y" ){
    global $post;
    $post = &get_post( $post_id );
    setup_postdata( $post );

    $modified_time = get_the_modified_time( $format );

    wp_reset_postdata( $post );

    return $modified_time;
}
Corrected error that printed out the date instead of returning it later.
Source Link

A late addition, but the following snippet can be modified to use most functions outside of the loop:

/**
 * Returns a post's modified date, formatted according to $format.
 * @uses the_modified_time()
 *
 * @param int $post_id Post ID.
 * @param string $format Date format Default: "F j, Y".
 */
function wpse95769_modified_date_by_id( $post_id = 0 , $format = "F j, Y" ){
    global $post;
 
    $post = &get_post( $post_id );
    setup_postdata( $post );

    $modified_time = the_modified_timeget_the_modified_time( $format );

    wp_reset_postdata( $post );

    return $modified_time;
}

A late addition, but the following snippet can be modified to use most functions outside of the loop:

/**
 * Returns a post's modified date, formatted according to $format.
 * @uses the_modified_time()
 *
 * @param int $post_id Post ID.
 * @param string $format Date format Default: "F j, Y".
 */
function wpse95769_modified_date_by_id( $post_id = 0 , $format = "F j, Y" ){
    global $post;
 
    $post = &get_post( $post_id );
    setup_postdata( $post );

    $modified_time = the_modified_time( $format );

    wp_reset_postdata( $post );

    return $modified_time;
}

A late addition, but the following snippet can be modified to use most functions outside of the loop:

/**
 * Returns a post's modified date, formatted according to $format.
 * @uses the_modified_time()
 *
 * @param int $post_id Post ID.
 * @param string $format Date format Default: "F j, Y".
 */
function wpse95769_modified_date_by_id($post_id = 0, $format = "F j, Y"){
    global $post;
    $post = &get_post($post_id);
    setup_postdata($post);

    $modified_time = get_the_modified_time($format);

    wp_reset_postdata($post);

    return $modified_time;
}
Source Link
Stephen Harris
  • 32.6k
  • 6
  • 84
  • 118

A late addition, but the following snippet can be modified to use most functions outside of the loop:

/**
 * Returns a post's modified date, formatted according to $format.
 * @uses the_modified_time()
 *
 * @param int $post_id Post ID.
 * @param string $format Date format Default: "F j, Y".
 */
function wpse95769_modified_date_by_id( $post_id = 0 , $format = "F j, Y" ){
    global $post;

    $post = &get_post( $post_id );
    setup_postdata( $post );

    $modified_time = the_modified_time( $format );

    wp_reset_postdata( $post );

    return $modified_time;
}