• The 6.5.x release of WordPress continues with a UI edit layout that end users have expressed adds additional manual steps (i.e. mouse clicks) to set an href hyperlink for Open in a New Tab (i.e. target=’_blank’).

    The issue has popped up across WordPress forum issues most recently here and here, as this editor functionality was rolled in 6.3.x through 6.4.x and thus I’m staging this for 6.5.x per moderator request.

    I think from a high level overview, the small but persistent chorus of end users complaining about this functionality change largely overlooks the fact that they are consumers of free & open source software — this is a persistent problem in OSS communities as the public has a false sense of entitlement in that complaints deserve the attention of unpaid open-source maintainers — @getdave outlines this nicely on a WP guttenberg git issue here.

    It is unclear to me how easy it is for WP maintainers to set a site wide configuration through the WP admin backend, that enables this Open in New Tab checkbox for all hyperlinks, that would probably alleviate a huge swath of complaints. I imagine a lot of CMS teams are either all of none for hyperlinks targetting blank into a new tab.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter atnjqt

    (@atnjqt)

    Actually maybe this was restored in 6.4.x but maybe is since changed in 6.5.x — I don’t manage content so this isn’t a problem for me, but I have been fielding complaints for WP sites I maintain!

    You can dothis youself witrh filters

    With AI generating this sort of thing is easy, this is AI generated but as an experience developer it looks sound

    add_filter('the_content', 'add_target_blank_to_links');
    
    function add_target_blank_to_links($content)
    {
        // parse the content
        $doc = new DOMDocument();
        $doc->loadHTML($content);
        $xpath = new DOMXPath($doc);
    
        // Get the domain of the site 
        $site_link = home_url();  
        $site_domain = parse_url($site_link, PHP_URL_HOST);  
    
        // Find links
        $links = $xpath->query('//a');
    
        foreach ($links as $link) {
            $href = $link->getAttribute('href');
    
            // Skip if link is empty
            if (empty($href)) {
                continue;
            }
    
            // Get the domain of the link
            $link_domain = parse_url($href, PHP_URL_HOST);
    
            // Skip if link if internal
            if ($link_domain == $site_domain || empty($link_domain)) {
                continue;
            }
    
            // Skip if link already has the attribute
            if ($link->getAttribute('target') === '_blank') {
                continue;
            }
    
            // Add target attribute
            $link->setAttribute('target', '_blank');
        }
    
        $html = $doc->saveHTML();
        return $html;  
    }
    • This reply was modified 4 months, 1 week ago by Alan Fuller.
Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.