Skip to content

fix(post-date): preserve classic theme markup and fix archive titles#4602

Merged
rbcorrales merged 3 commits intotrunkfrom
fix/post-date-markup
Apr 2, 2026
Merged

fix(post-date): preserve classic theme markup and fix archive titles#4602
rbcorrales merged 3 commits intotrunkfrom
fix/post-date-markup

Conversation

@rbcorrales
Copy link
Copy Markdown
Member

All Submissions:

Changes proposed in this Pull Request:

Follow-up to #4579. Addresses review feedback from @laurelfulford about preserving the classic theme's HTML markup for the updated date, and fixes the archive title regression.

  • Renamed hook from newspack_theme_after_posted_on to newspack_theme_posted_on (now fires inside newspack_posted_on() in the theme)
  • Changed classic theme output to bare inner elements (<span class="updated-label"> + <time class="updated">) matching the old theme markup exactly
  • Removed plugin's inline CSS for .updated-date (theme provides .updated-label styling)
  • Added in_the_loop() guard to filter_get_the_date to prevent archive titles showing relative dates (e.g. "Daily Archives: 2 days ago")
  • Added time.updated[datetime] to the relative-time JS selector so the updated date gets a hover tooltip on classic themes

Requires companion theme PR: Automattic/newspack-theme#2658. Must ship together.

Closes NPPD-1278.

How to test the changes in this Pull Request:

  1. Activate the classic Newspack theme (with the companion theme PR) and enable both "Show relative dates" and "Show last updated date" in Newspack > Settings > Advanced Settings > Post Date.
  2. Create or find a post modified well after publication (at least 24 hours). Verify the markup is all inside one .posted-on span: <time class="entry-date published"> + <span class="updated-label">Updated </span> + <time class="updated">.
  3. Hover over both dates and verify both show a tooltip with the full date.
  4. Visit a daily archive page and verify the title shows the full date, not "X days ago".
  5. Switch to the block theme. Verify the updated date still renders correctly with data-newspack-modified and wp-block-post-date__modified-date.
  6. Open a post in the block editor. Verify the "Hide/Show last updated date" toggle appears in the Summary panel.

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully ran tests with your changes locally?

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adjusts the Post Date feature integration to better match the classic Newspack theme’s historical markup while preventing relative-date formatting from leaking into archive titles.

Changes:

  • Switch classic-theme updated-date injection to the new newspack_theme_posted_on hook and adjust classic updated-date HTML output to match legacy markup.
  • Prevent get_the_date “time ago” conversion from applying outside the loop (fixes archive title regressions).
  • Update the relative-time JS to also target time.updated[datetime] and remove the plugin’s classic updated-date inline CSS.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
includes/class-post-date.php Renames the classic-theme hook, updates classic updated-date markup, removes inline CSS, and adds an in_the_loop() guard in get_the_date filtering.
src/other-scripts/relative-time/index.js Expands the selector to include time.updated[datetime] so classic updated dates get tooltips/updates.
tests/unit-tests/class-post-date-test.php Updates the get_the_date filter test to simulate being “in the loop”.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@rbcorrales rbcorrales marked this pull request as ready for review March 26, 2026 18:28
@rbcorrales rbcorrales requested a review from a team as a code owner March 26, 2026 18:28
@rbcorrales rbcorrales added the [Status] Needs Review The issue or pull request needs to be reviewed label Mar 26, 2026
@github-actions github-actions bot added [Status] Approved The pull request has been reviewed and is ready to merge and removed [Status] Needs Review The issue or pull request needs to be reviewed labels Mar 31, 2026
@laurelfulford laurelfulford self-requested a review March 31, 2026 17:02
Copy link
Copy Markdown
Contributor

@laurelfulford laurelfulford left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't had a chance to give this one a full review yet (sorry!), but it looks like the hidden 'updated' dates might be missing -- this is something that some publishers are using CSS to show to "roll their own" show updated date option.

When I edit a post, I get:

Image

... compared to the same post in the Content Loop block -- the markup does differ, but the bit that's missing from the single post is the second, hidden <time> tag.

Image

That second <time> should start showing up as soon as the post it edited.

It's a weird edge case for folks using this, but it'd be nice to preserve it!

@github-actions github-actions bot added [Status] Needs Changes or Feedback The issue or pull request needs action from the original creator and removed [Status] Approved The pull request has been reviewed and is ready to merge labels Mar 31, 2026
@rbcorrales
Copy link
Copy Markdown
Member Author

@laurelfulford good catch! I missed that on the previous theme PR.

The hidden <time class="updated"> is restored in the companion theme PR (88daed7). The theme's newspack_posted_on() now always outputs <time class="updated"> when dates differ, hidden by .updated:not(.published) { display: none }. It should continue working as expected for publishers with custom CSS.

image

@rbcorrales rbcorrales requested a review from laurelfulford April 1, 2026 04:23
@rbcorrales rbcorrales added [Status] Needs Review The issue or pull request needs to be reviewed and removed [Status] Needs Changes or Feedback The issue or pull request needs action from the original creator labels Apr 1, 2026
Copy link
Copy Markdown
Contributor

@laurelfulford laurelfulford left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @rbcorrales!

The markup looks good! One remaining issue: the updated CSS now hides the updated date when you want to show it 😅

CleanShot 2026-04-01 at 11 56 04

This was previously shown in the theme by adding a CSS class on the body, and using it to style the date as visible:

// Add a class if updated date should display
if ( newspack_should_display_updated_date() ) {
	$classes[] = 'show-updated';
}
.show-updated .entry-header .updated:not(.published) {
	display: inline-block;
}

@github-actions github-actions bot added the [Status] Needs Changes or Feedback The issue or pull request needs action from the original creator label Apr 1, 2026
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@rbcorrales rbcorrales requested a review from laurelfulford April 2, 2026 15:00
@rbcorrales
Copy link
Copy Markdown
Member Author

@laurelfulford thank you for spotting this. Fixed in b998513 and 4d0975f (theme).

The tricky part was avoiding a duplicate <time class="updated">, since the theme always outputs a hidden one (for sites that show it via custom CSS) and the plugin outputs another when the feature is on. If both are visible, you get the date twice.

The fix adds a filter (newspack_theme_include_hidden_updated_time) so the plugin can suppress the theme's hidden <time> when it's handling the updated date itself. The plugin adds the show-updated body class (same as the old theme) and the theme CSS uses .show-updated .entry-header .updated-label + .updated:not(.published) { display: inline } to reveal only the plugin's date. This keeps the plugin in full control of content and formatting (including time ago) when the feature is active.

Tested:

  • Feature ON/OFF with classic theme
  • Custom CSS that targets the hidden <time class="updated"> in both states (no duplicates, the :has( > .updated-label ) selector correctly suppresses the CSS prefix when the plugin's label is present)
  • Block theme: unaffected

Copy link
Copy Markdown
Contributor

@laurelfulford laurelfulford left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @rbcorrales! This looks good to me - I also tested with a snippet of CSS used by a publisher to manipulate how the dates look, still works as expected with this change! 🎉

@github-actions github-actions bot added [Status] Approved The pull request has been reviewed and is ready to merge and removed [Status] Needs Review The issue or pull request needs to be reviewed [Status] Needs Changes or Feedback The issue or pull request needs action from the original creator labels Apr 2, 2026
@rbcorrales rbcorrales merged commit c5fb825 into trunk Apr 2, 2026
9 checks passed
@rbcorrales rbcorrales deleted the fix/post-date-markup branch April 2, 2026 16:17
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 2, 2026

Hey @rbcorrales, good job getting this PR merged! 🎉

Now, the needs-changelog label has been added to it.

Please check if this PR needs to be included in the "Upcoming Changes" and "Release Notes" doc. If it doesn't, simply remove the label.

If it does, please add an entry to our shared document, with screenshots and testing instructions if applicable, then remove the label.

Thank you! ❤️

matticbot pushed a commit that referenced this pull request Apr 2, 2026
# [6.37.0-alpha.1](v6.36.1...v6.37.0-alpha.1) (2026-04-02)

### Bug Fixes

* **card-settings-group:** change default actionType from chevron to none ([#4610](#4610)) ([00505ed](00505ed))
* **post-date:** preserve classic theme markup and fix archive titles ([#4602](#4602)) ([c5fb825](c5fb825))
* remove removal of block visibility ([#4595](#4595)) ([9396379](9396379))

### Features

* **access-control:** filter available lists by content restrictions ([#4589](#4589)) ([959127f](959127f)), closes [#4581](#4581) [#4583](#4583) [#4590](#4590)
* **access-control:** premium newsletters UI ([#4577](#4577)) ([6f8c891](6f8c891)), closes [#4581](#4581) [#4583](#4583) [#4590](#4590)
* **author-profile-social:** add support for colors, block spacing, brand style ([#4509](#4509)) ([21cf4c9](21cf4c9))
* campaigns wizard light UI refresh ([#4588](#4588)) ([6078c4b](6078c4b))
* **color-picker:** simplify component to use basecontrol ([#4581](#4581)) ([ff677ea](ff677ea))
* **components:** add CardFeature component ([#4583](#4583)) ([5aabb18](5aabb18))
* **content-gate:** institution management ui ([#4582](#4582)) ([ae88750](ae88750))
* **content-gate:** institutional access redirect and loading UX ([#4593](#4593)) ([548d236](548d236))
* **content-gate:** institutions ([#4574](#4574)) ([49b0c05](49b0c05))
* **content-gate:** personalized institutional access verification page ([#4596](#4596)) ([0eed591](0eed591))
* **image-upload:** simplify component to use basecontrol; remove info prop ([#4580](#4580)) ([d51eb54](d51eb54))
* **integrations:** add ActionScheduler group handling ([#4559](#4559)) ([411732a](411732a))
* **integrations:** promoted fields for content gate and campaign segmentation ([#4601](#4601)) ([f943df2](f943df2))
* **newspack-ui:** add stack layout and color utility classes ([#4600](#4600)) ([1934067](1934067))
* **post-date:** centralize date features from theme into plugin ([#4579](#4579)) ([19f15eb](19f15eb))
* **sync:** prevent stale data on retry, improve logging and error handling ([#4562](#4562)) ([5467f34](5467f34))
* **tags:** add private tags feature ([#4507](#4507)) ([06d7711](06d7711))
* **yoast:** add primary category utility and settings toggle ([#4563](#4563)) ([4b396c3](4b396c3))
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 2, 2026

🎉 This PR is included in version 6.37.0-alpha.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Status] Approved The pull request has been reviewed and is ready to merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants