• 07-12-2022, 14:25:36
    #1
    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);
  • 07-12-2022, 14:29:47
    #2
    İç bağlantıların yeni sekmede açılmamasını ve herhangi bir rel etiketi almamasını, dış bağlantılar yani site içerisinde olmayan bağlantıların yeni sekmede açılmasını sağlıyor.
  • 07-12-2022, 14:32:22
    #3
    @v4r1able; teşekkürler.