fauzanjeg

Change Post Date Format (Ago)

Mar 8th, 2021 (edited)
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.94 KB | None | 0 0
  1. /* Change Post Date Format (Ago) */
  2. function jnews_ago_time( $post = null ) {
  3.     $publish_date = human_time_diff( get_post_timestamp($post, 'date'), current_time( 'timestamp' ) );
  4.     $modified_date = human_time_diff( get_post_timestamp($post, 'modified'), current_time( 'timestamp' ) );
  5.  
  6.     if ( get_theme_mod( 'jnews_global_post_date', 'modified' ) === 'publish' ) {
  7.         return esc_html(
  8.             sprintf(
  9.                 jnews_return_translation( '%s ago', 'jnews', 'sago' ),
  10.                 $publish_date
  11.             )
  12.         );
  13.     } elseif ( get_theme_mod( 'jnews_global_post_date', 'modified' ) === 'both' ) {
  14.         return esc_html(
  15.             sprintf(
  16.                 jnews_return_translation( 'Published %s ago, Modified %s ago', 'jnews', 'sagoboth' ),
  17.                 $publish_date, $modified_date
  18.             )
  19.         );
  20.     } elseif ( get_theme_mod( 'jnews_global_post_date', 'modified' ) === 'modified' ) {
  21.         return esc_html(
  22.             sprintf(
  23.                 jnews_return_translation( '%s ago', 'jnews', 'sago' ),
  24.                 $modified_date
  25.             )
  26.         );
  27.     }
  28. }
Add Comment
Please, Sign In to add comment