From b143a363cc61dbe271ae5e18db45fd9a9188ead7 Mon Sep 17 00:00:00 2001 From: Yannic van Veen Date: Wed, 1 Apr 2026 11:51:08 +0200 Subject: [PATCH 1/3] feat: strip new tab notice from excerpts / make new tab notice configurable --- src/Theme.php | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/Theme.php b/src/Theme.php index 42665ae..9b52a3d 100644 --- a/src/Theme.php +++ b/src/Theme.php @@ -13,6 +13,13 @@ class Theme { use ParentPage; + private string $newTabNotice; + + public function __construct() + { + $this->newTabNotice = config('theme.a11y_new_tab_notice', __(' (opent in nieuw tabblad)', 'sage')); + } + /** * Disable WordPress from changing smilies (also known as smileys) into emojis. * @@ -198,7 +205,7 @@ public function filterA11yProblematicHtmlTags(string $content): string } try { - $srOnlySpan = $doc->createElement('span', ' (opent in nieuw tabblad)'); + $srOnlySpan = $doc->createElement('span', ' ' . $this->newTabNotice); } catch (\DOMException $e) { continue; } @@ -236,6 +243,21 @@ public function filterA11yProblematicHtmlTags(string $content): string return '' === $newContent ? $content : $newContent; } + /** + * Strips the new tab notice from excerpts and removes the extra space + */ + #[Filter('get_the_excerpt')] + public function stripNewTabNoticeFromExcerpt(string $excerpt, \WP_Post $post): string + { + if (has_excerpt($post)) { + return $excerpt; + } + + $strippedExcerpt = str_replace($this->newTabNotice, '', $excerpt); + + return preg_replace('/\s{2,}/', ' ', trim($strippedExcerpt)); + } + /** * Remove the outer div that was added for fragment safety. */ From f7489747897bf645d6398f06c5817b5ce1e2a4c5 Mon Sep 17 00:00:00 2001 From: Yannic van Veen Date: Wed, 1 Apr 2026 12:02:38 +0200 Subject: [PATCH 2/3] feat: remove leading space from default notice --- src/Theme.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Theme.php b/src/Theme.php index 9b52a3d..2c28490 100644 --- a/src/Theme.php +++ b/src/Theme.php @@ -17,7 +17,7 @@ class Theme public function __construct() { - $this->newTabNotice = config('theme.a11y_new_tab_notice', __(' (opent in nieuw tabblad)', 'sage')); + $this->newTabNotice = config('theme.a11y_new_tab_notice', __('(opent in nieuw tabblad)', 'sage')); } /** From 489b5294f0e9268ce7a725a1b69d6fae03061fe1 Mon Sep 17 00:00:00 2001 From: Yannic van Veen Date: Wed, 1 Apr 2026 12:11:52 +0200 Subject: [PATCH 3/3] feat: add early return if excerpt does not contain new tab notice / add null coalescing to preg_replace --- src/Theme.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Theme.php b/src/Theme.php index 2c28490..65701c9 100644 --- a/src/Theme.php +++ b/src/Theme.php @@ -255,7 +255,11 @@ public function stripNewTabNoticeFromExcerpt(string $excerpt, \WP_Post $post): s $strippedExcerpt = str_replace($this->newTabNotice, '', $excerpt); - return preg_replace('/\s{2,}/', ' ', trim($strippedExcerpt)); + if ($strippedExcerpt === $excerpt) { + return $excerpt; + } + + return preg_replace('/\s{2,}/', ' ', trim($strippedExcerpt)) ?? $strippedExcerpt; } /**