Advertisement
fauzanjeg

Show Time in Post Date Meta

Aug 6th, 2021
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.48 KB | None | 0 0
  1. /* Show Time in Post Date Meta */
  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.     $publish_date .= ' - ' . get_post_time( 'h:i A', null, $post );
  9.     $modified_date .= ' - ' . get_post_time( 'h:i A', null, $post );
  10.  
  11.     if ( get_theme_mod( 'jnews_global_post_date', 'modified' ) === 'publish' ) {
  12.         return $publish_date;
  13.     } elseif ( get_theme_mod( 'jnews_global_post_date', 'modified' ) === 'both' ) {
  14.         if ( strtotime( $publish_date_number_format ) >= strtotime( $modified_date_number_format ) ) {
  15.             return $publish_date;
  16.         } else {
  17.             return $publish_date . ' - ' . jnews_return_translation( 'Updated on', 'jnews', 'updated_on' ) . ' ' . $modified_date;
  18.         }
  19.     } elseif ( get_theme_mod( 'jnews_global_post_date', 'modified' ) === 'modified' ) {
  20.         if ( strtotime( $publish_date_number_format ) >= strtotime( $modified_date_number_format ) ) {
  21.             return $publish_date;
  22.         } else {
  23.             return $modified_date;
  24.         }
  25.     }
  26.  
  27.     return $publish_date;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement