diff --git a/includes/class-post-date.php b/includes/class-post-date.php
index f067cd6b46..7663c2c9a2 100644
--- a/includes/class-post-date.php
+++ b/includes/class-post-date.php
@@ -52,7 +52,9 @@ public static function init() {
add_filter( 'newspack_blocks_formatted_displayed_post_date', [ __CLASS__, 'filter_blocks_formatted_date' ], 10, 2 );
add_action( 'wp_enqueue_scripts', [ __CLASS__, 'enqueue_scripts' ] );
add_action( 'enqueue_block_editor_assets', [ __CLASS__, 'enqueue_editor_assets' ] );
- add_action( 'newspack_theme_after_posted_on', [ __CLASS__, 'render_updated_date_classic' ] );
+ add_action( 'newspack_theme_posted_on', [ __CLASS__, 'render_updated_date_classic' ] );
+ add_filter( 'body_class', [ __CLASS__, 'add_body_show_updated' ] );
+ add_filter( 'newspack_theme_include_hidden_updated_time', [ __CLASS__, 'suppress_theme_hidden_updated_time' ] );
}
/**
@@ -257,6 +259,12 @@ public static function filter_get_the_date( $the_date, $format, $post ) {
return $the_date;
}
+ // Only convert dates in the loop to avoid affecting archive titles
+ // (e.g. "Daily Archives: 2 days ago") and other contexts.
+ if ( ! in_the_loop() ) {
+ return $the_date;
+ }
+
$time_ago = self::convert_to_time_ago( $post->post_date_gmt, self::get_time_ago_cutoff_days() );
return null !== $time_ago ? $time_ago : $the_date;
@@ -281,7 +289,7 @@ public static function filter_blocks_formatted_date( $date, $post ) {
/**
* Render updated date for classic (non-block) themes.
- * Hooked to `newspack_theme_after_posted_on` which fires after `newspack_posted_on()`.
+ * Hooked to `newspack_theme_posted_on` which fires inside `newspack_posted_on()`.
*/
public static function render_updated_date_classic() {
if ( wp_is_block_theme() || ! is_singular() ) {
@@ -306,16 +314,46 @@ public static function render_updated_date_classic() {
}
}
- /* translators: %s: Modified date. */
- $label = sprintf( esc_html__( 'Updated %s', 'newspack-plugin' ), $modified_date );
-
printf(
- '',
+ '%1$s ',
+ esc_html__( 'Updated', 'newspack-plugin' ),
esc_attr( get_the_modified_date( DATE_W3C, $post ) ),
- wp_kses_post( $label )
+ esc_html( $modified_date )
);
}
+ /**
+ * Add 'show-updated' body class when the updated date should display on classic themes.
+ *
+ * @param string[] $classes Body CSS classes.
+ * @return string[]
+ */
+ public static function add_body_show_updated( $classes ) {
+ if ( wp_is_block_theme() || ! is_singular() ) {
+ return $classes;
+ }
+ if ( self::should_display_updated_date() ) {
+ $classes[] = 'show-updated';
+ }
+ return $classes;
+ }
+
+ /**
+ * Suppress the theme's hidden