This powerhouse 2026 guide, tailored for searches like "open external links new tab WordPress no plugin" (up 55% YoY), unleashes 7 proven ways to open all external links in new window or new tab without a WordPress plugin. From simple JS snippets to content filters, these work on Gutenberg, Classic Editor, and themes like Astra. Let's retain traffic effortlessly!
Why Open All External Links in New Window or New Tab Without a WordPress Plugin?
Internal links stay on-site; external ones navigate away—opening in new tabs/windows prevents loss while maintaining flow. In 2026:
Retention Boost → Users multitab, returning easier.
SEO Indirect Win → Longer sessions signal quality.
Accessibility Note → Add rel="noopener" for security/performance.
No Plugin Perks → Lighter site, no updates.
Manual per-link is tedious—automation rules.
Method 1: JavaScript Snippet – Automatic for All External Links
The gold standard: JS targets external anchors.
Steps:
Add to child theme's functions.php (or Customizer > Additional JS): // Open all external links in new window or new tab without WordPress plugin
document.addEventListener('DOMContentLoaded', function() {
var links = document.querySelectorAll('a[href^="http"]:not([href*="'+window.location.hostname+'"])');
links.forEach(function(link) {
link.setAttribute('target', '_blank');
link.setAttribute('rel', 'noopener noreferrer'); // Security best practice
});
});
Save—external links auto-open in new tabs.
Works site-wide, including content/menus.
Method 2: Content Filter – Add target=_blank on Save
PHP filter modifies links in posts/pages.
Code (functions.php): function external_links_new_tab($content) {
return preg_replace_callback('/]+href="\'["\'][^>]*>/i', function($matches) {
$href = $matches[1];
if (strpos($href, home_url()) === false) {
return str_replace('<a ', '<a target="_blank" rel="noopener noreferrer" ', $matches[0]);
}
return $matches[0];
}, $content);
}
add_filter('the_content', 'external_links_new_tab', 999);
Applies to post content only—safe for existing links.
Method 3: Gutenberg Default – Manual Checkbox Easier
No auto, but streamline.
In Editor:
Add link > Gear icon > Toggle Open in new tab.
For menus: Appearance > Menus > Expand item > Check "Open link in a new tab".
Consistent manual control.
Method 4: Footer JS Enqueue – Proper Loading
Enqueue for performance.
functions.php:
PHP
function external_links_js() {
wp_enqueue_script('external-links', get_stylesheet_directory_uri() . '/js/external.js', array(), '1.0', true);
}
add_action('wp_enqueue_scripts', 'external_links_js');
Create /js/external.js with Method 1 code.
Method 5: Base Target – Simple but Site-Wide (Caution)
Head-level override.
In header.php (before ):
HTML
Opens everything new—add exceptions via _self.
Risky for internal nav—use sparingly.
Method 6: Menu-Specific – For Navigation Only
Target menus.
functions.php:
PHP
add_filter('nav_menu_link_attributes', function($atts, $item, $args) {
if (strpos($atts['href'], home_url()) === false) {
$atts['target'] = '_blank';
$atts['rel'] = 'noopener noreferrer';
}
return $atts;
}, 999, 3);
Menus only—content untouched.
Method 7: Hybrid – JS + Filter for Robust Coverage
Combine Method 1 (JS) and 2 (filter)—catches dynamic/content.
Add both—ultimate reliability.
Comparison Table: Ways to Open All External Links in New Window or New Tab Without a WordPress Plugin
MethodEaseScopeSecurity (noopener)Best ForJS SnippetEasySite-wideYesMost sitesContent FilterMediumPosts/PagesYesContent-heavyGutenberg ManualEasyPer-linkManualControlledEnqueue JSMediumSite-wideYesPerformanceBase TargetEasyAll linksNoSimple sitesMenu FilterMediumNavigationYesMenus onlyHybridAdvancedFullYesBulletproof
Best Practices for External Links in New Tabs 2026
Always noopener — Prevents tabnabbing/security risks.
Test Mobile — New tabs work differently on touch.
ARIA Labels — Add "opens in new tab" for accessibility.
Child Theme — Safe code additions.
Clear Cache — Post-changes.
For more, see Perishable Press guide (external DoFollow) or our archive title cleanup (internal link).
~1% density on open all external links in new window or new tab without a WordPress plugin—natural flow.
Conclusion: Retain Visitors Seamlessly
Implement how to open all external links in new window or new tab without a WordPress plugin with these 7 proven ways—your traffic stays while sharing value. Start with the JS snippet for quick wins.
Which method kept your users? Comment below and follow my social media to keep up with my tips and tutorials. we're linking WP smarter!
Updated January 19, 2026 | Compatible with WordPress 6.7+
Top comments (0)