另一种方法是使用in_array
. 如果您的支票失败,您也不会返回原始日期。有关修复,请参阅下面的代码。
function et_last_modified_date_blog( $the_date ) {
// all post types were are checking for
$post_types = array(\'post\', \'movies\');
// check to see if current post type is in the $post_types array
if (in_array(get_post_type(), $post_types)) {
$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\' ) ) );
$date = $the_modified !== $the_time ? $last_modified : get_post_time( \'M j, Y\' );
return $date;
}
// NOTE: you should return the original date here in case your check "fails"
return $the_date;
}
add_action( \'get_the_date\', \'et_last_modified_date_blog\' );
add_action( \'get_the_time\', \'et_last_modified_date_blog\' );