Advertisement
fauzanjeg

Show the modified date except though it's never been modified

Jul 25th, 2021
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.34 KB | None | 0 0
  1. /* Show the modified date except though it's never been modified */
  2. function jeg_get_post_date( $format = '', $post = null ) {
  3.     $publish_date  = isset( $post->publish_date ) ? date( $format ?: 'Y-m-d', $post->publish_date ) : get_the_date( $format, $post );
  4.     $modified_date = isset( $post->update_date ) ? date( $format ?: 'Y-m-d', $post->update_date ) : get_the_modified_date( $format, $post );
  5.     $publish_date_number_format  = isset( $post->publish_date ) ? date( 'Y-m-d', $post->publish_date ) : get_the_date( 'Y-m-d', $post );
  6.     $modified_date_number_format = isset( $post->update_date ) ? date( 'Y-m-d', $post->update_date ) : get_the_modified_date( 'Y-m-d', $post );
  7.  
  8.     if ( get_theme_mod( 'jnews_global_post_date', 'modified' ) === 'publish' ) {
  9.         return $publish_date;
  10.     } elseif ( get_theme_mod( 'jnews_global_post_date', 'modified' ) === 'both' ) {
  11.         if ( count( wp_get_post_revisions( $post ) ) === 0 ) {
  12.             return $publish_date;
  13.         } else {
  14.             return $publish_date . ' - ' . jnews_return_translation( 'Updated on', 'jnews', 'updated_on' ) . ' ' . $modified_date;
  15.         }
  16.     } elseif ( get_theme_mod( 'jnews_global_post_date', 'modified' ) === 'modified' ) {
  17.         if ( strtotime( $publish_date_number_format ) >= strtotime( $modified_date_number_format ) ) {
  18.             return $publish_date;
  19.         } else {
  20.             return $modified_date;
  21.         }
  22.     }
  23.  
  24.     return $publish_date;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement