Advertisement
fauzanjeg

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

Jul 23rd, 2021
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.24 KB | None | 0 0
  1. /* Show the modified date even 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.         return $publish_date . ' - ' . jnews_return_translation( 'Updated on', 'jnews', 'updated_on' ) . ' ' . $modified_date;
  12.     } elseif ( get_theme_mod( 'jnews_global_post_date', 'modified' ) === 'modified' ) {
  13.         if ( strtotime( $publish_date_number_format ) >= strtotime( $modified_date_number_format ) ) {
  14.             return $publish_date;
  15.         } else {
  16.             return $modified_date;
  17.         }
  18.     }
  19.  
  20.     return $publish_date;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement