Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion src/Theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -236,6 +243,25 @@ 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);

if ($strippedExcerpt === $excerpt) {
return $excerpt;
}

return preg_replace('/\s{2,}/', ' ', trim($strippedExcerpt)) ?? $strippedExcerpt;
}

/**
* Remove the outer div that was added for fragment safety.
*/
Expand Down
Loading