Duplicate Snippet
Embed Snippet on Your Site
Open External link to a new tab
This code snippet enhances a WordPress website by automatically opening external links in new tabs. When applied, the script runs after the page has loaded, identifying all hyperlinks within the content. If a link's destination differs from the current page's hostname, it modifies the link attributes to ensure it opens in a new browser tab, enhancing the user experience. This functionality improves website navigation by providing a seamless transition for visitors accessing external resources, contributing to a more user-friendly browsing environment.
Code Preview
php
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
Comments