From e91321dd0f43410df8c9da0797a5acb388983d57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Flo=CC=88ter?= Date: Thu, 5 Nov 2026 13:46:40 +0100 Subject: [PATCH 1/2] General: Show the week in the title of weekly archives. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Weekly archive links contain both the year and the week (`?m=2025&w=39`), so `is_year()` is true and `get_the_archive_title()` and `wp_get_document_title()` used the year as the title. Add a week branch before the year check in both functions. It uses the same date range as the weekly archive links from `wp_get_archives()`, e.g. "Week: September 22, 2025 – September 28, 2025". See #66489. Co-Authored-By: Claude Opus 5.5 --- src/wp-includes/general-template.php | 27 ++++++ .../tests/general/getTheArchiveTitle.php | 91 +++++++++++++++++++ .../tests/general/wpGetDocumentTitle.php | 11 +++ 3 files changed, 129 insertions(+) create mode 100644 tests/phpunit/tests/general/getTheArchiveTitle.php diff --git a/src/wp-includes/general-template.php b/src/wp-includes/general-template.php index eb6e185f5b49d..28678a66be258 100644 --- a/src/wp-includes/general-template.php +++ b/src/wp-includes/general-template.php @@ -1484,6 +1484,21 @@ function wp_get_document_title() { $author = get_queried_object(); $title['title'] = $author->display_name; + /* + * If it's a weekly archive, use the week's date range as the title. + * Weekly archive links also contain the year, so check this before is_year(). + */ + } elseif ( is_date() && get_query_var( 'w' ) && get_the_date( 'Y-m-d' ) ) { + $week = get_weekstartend( get_the_date( 'Y-m-d' ), get_option( 'start_of_week' ) ); + $date_format = get_option( 'date_format' ); + + $title['title'] = sprintf( + /* translators: 1: Week start date, 2: Week end date. */ + _x( '%1$s – %2$s', 'weekly archives date range' ), + date_i18n( $date_format, $week['start'] ), + date_i18n( $date_format, $week['end'] ) + ); + // If it's a date archive, use the date as the title. } elseif ( is_year() ) { $title['title'] = get_the_date( _x( 'Y', 'yearly archives date format' ) ); @@ -2005,6 +2020,18 @@ function get_the_archive_title() { } elseif ( is_author() ) { $title = get_the_author(); $prefix = _x( 'Author:', 'author archive title prefix' ); + } elseif ( is_date() && get_query_var( 'w' ) && get_the_date( 'Y-m-d' ) ) { + // Weekly archive links also contain the year, so check this before is_year(). + $week = get_weekstartend( get_the_date( 'Y-m-d' ), get_option( 'start_of_week' ) ); + $date_format = get_option( 'date_format' ); + + $title = sprintf( + /* translators: 1: Week start date, 2: Week end date. */ + _x( '%1$s – %2$s', 'weekly archives date range' ), + date_i18n( $date_format, $week['start'] ), + date_i18n( $date_format, $week['end'] ) + ); + $prefix = _x( 'Week:', 'date archive title prefix' ); } elseif ( is_year() ) { /* translators: See https://www.php.net/manual/datetime.format.php */ $title = get_the_date( _x( 'Y', 'yearly archives date format' ) ); diff --git a/tests/phpunit/tests/general/getTheArchiveTitle.php b/tests/phpunit/tests/general/getTheArchiveTitle.php new file mode 100644 index 0000000000000..ed91cad5eb6c1 --- /dev/null +++ b/tests/phpunit/tests/general/getTheArchiveTitle.php @@ -0,0 +1,91 @@ +post->create( + array( + 'post_status' => 'publish', + 'post_date' => '2015-09-22 18:52:17', + ) + ); + } + + public function set_up() { + parent::set_up(); + + update_option( 'start_of_week', 1 ); + update_option( 'date_format', 'F j, Y' ); + } + + /** + * Tests that a weekly archive uses the week's date range, not the year. + * + * @ticket 66489 + */ + public function test_get_the_archive_title_on_weekly_archive() { + $this->go_to( '?m=2015&w=39' ); + + $this->assertTrue( is_year(), 'Weekly archive links also set is_year().' ); + $this->assertSame( 'Week: September 21, 2015 – September 27, 2015', get_the_archive_title() ); + } + + /** + * Tests that a weekly archive respects the start_of_week option. + * + * @ticket 66489 + */ + public function test_get_the_archive_title_on_weekly_archive_respects_start_of_week() { + update_option( 'start_of_week', 0 ); + + $this->go_to( '?m=2015&w=38' ); + + $this->assertSame( 'Week: September 20, 2015 – September 26, 2015', get_the_archive_title() ); + } + + /** + * Tests that a weekly archive without the year uses the week's date range. + * + * @ticket 66489 + */ + public function test_get_the_archive_title_on_weekly_archive_without_year() { + $this->go_to( '?w=39' ); + + $this->assertSame( 'Week: September 21, 2015 – September 27, 2015', get_the_archive_title() ); + } + + /** + * @ticket 66489 + */ + public function test_get_the_archive_title_on_yearly_archive() { + $this->go_to( '?m=2015' ); + + $this->assertSame( 'Year: 2015', get_the_archive_title() ); + } + + /** + * @ticket 66489 + */ + public function test_get_the_archive_title_on_monthly_archive() { + $this->go_to( '?m=201509' ); + + $this->assertSame( 'Month: September 2015', get_the_archive_title() ); + } + + /** + * @ticket 66489 + */ + public function test_get_the_archive_title_on_daily_archive() { + $this->go_to( '?m=20150922' ); + + $this->assertSame( 'Day: September 22, 2015', get_the_archive_title() ); + } +} diff --git a/tests/phpunit/tests/general/wpGetDocumentTitle.php b/tests/phpunit/tests/general/wpGetDocumentTitle.php index df83ffbfc2de9..491e922ad00a8 100644 --- a/tests/phpunit/tests/general/wpGetDocumentTitle.php +++ b/tests/phpunit/tests/general/wpGetDocumentTitle.php @@ -240,6 +240,17 @@ public function test_day_title() { $this->assertSame( sprintf( 'September 22, 2015 – %s', $this->blog_name ), wp_get_document_title() ); } + /** + * @ticket 66489 + */ + public function test_week_title() { + update_option( 'start_of_week', 1 ); + + $this->go_to( '?m=2015&w=39' ); + + $this->assertSame( sprintf( 'September 21, 2015 – September 27, 2015 – %s', $this->blog_name ), wp_get_document_title() ); + } + public function test_404_title() { $this->go_to( '?m=404' ); From c059a75e3995eabcd8b174c8d879aec15e9a50df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Flo=CC=88ter?= Date: Sun, 29 Nov 2026 20:22:43 +0100 Subject: [PATCH 2/2] Tests: Cover weekly archive document title without the year. Add a test for `wp_get_document_title()` on `?w=39`, where only the week is set. See #66489. Co-Authored-By: Claude Opus 5.5 --- tests/phpunit/tests/general/wpGetDocumentTitle.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/phpunit/tests/general/wpGetDocumentTitle.php b/tests/phpunit/tests/general/wpGetDocumentTitle.php index 491e922ad00a8..aa906dbff991d 100644 --- a/tests/phpunit/tests/general/wpGetDocumentTitle.php +++ b/tests/phpunit/tests/general/wpGetDocumentTitle.php @@ -251,6 +251,17 @@ public function test_week_title() { $this->assertSame( sprintf( 'September 21, 2015 – September 27, 2015 – %s', $this->blog_name ), wp_get_document_title() ); } + /** + * @ticket 66489 + */ + public function test_week_title_without_year() { + update_option( 'start_of_week', 1 ); + + $this->go_to( '?w=39' ); + + $this->assertSame( sprintf( 'September 21, 2015 – September 27, 2015 – %s', $this->blog_name ), wp_get_document_title() ); + } + public function test_404_title() { $this->go_to( '?m=404' );