rayhan21

Add Post Updated Date on GeneratePress Theme

Jun 15th, 2021
636
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. add_filter( 'generate_post_date_output', function( $output, $time_string ) {
  2.     $time_string = '<time class="entry-date published" datetime="%1$s" itemprop="datePublished">%2$s</time>';
  3.  
  4.     if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
  5.         $time_string = '<time class="entry-date updated-date" datetime="%3$s" itemprop="dateModified">Last Updated on: %4$s</time>';
  6.     }
  7.  
  8.     $time_string = sprintf( $time_string,
  9.         esc_attr( get_the_date( 'c' ) ),
  10.         esc_html( get_the_date() ),
  11.         esc_attr( get_the_modified_date( 'c' ) ),
  12.         esc_html( get_the_modified_date() )
  13.     );
  14.  
  15.     return sprintf( '<span class="posted-on">%s</span> ',
  16.         $time_string
  17.     );
  18. }, 10, 2 );
RAW Paste Data