functions.php'ye ekleniyormuş. Linklerle ilgili ama ne olduğunu anlamadım.
/**
* Modifies internal/external links. Strips target and rel from internal links
* so that they are not opened in a new window. Adds target="_blank" to external
* links so that they are opened in a new window.
*
* If this behavior is not desired on a link add the CSS class NO_MODIFY to the
* link.
*/
function modifyLinks(string $htmlString, array $internalDomains) {
$html = new DOMDocument();
@$html->loadHTML(''.$htmlString);
foreach($html->getElementsByTagName('a') as $a) {
// skip links that have a CSS class of NO_MODIFY
if (strpos($a->getAttribute('class'),'NO_MODIFY') !== false) {
continue;
}
$url = parse_url($a->getAttribute('href'));
if (empty($url['host']) || in_array($url['host'], $internalDomains)) {
// Internal Link
$a->removeAttribute('target');
$a->removeAttribute('rel');
} else {
// External Link
$a->setAttribute('target','_blank');
}
}
return $html->saveHTML($html->documentElement);
}
add_filter('the_content', static function($content) {
return modifyLinks($content, array('domain.com','subdomain.domain.com'));
},99);