Open outside links in a new tab
Links in your posts and pages that go to other sites open in a new tab. Menus and footers aren’t changed.
// Only links inside post and page content.
document.querySelectorAll( '.entry-content a[href], .wp-block-post-content a[href]' ).forEach( function ( link ) {
if ( /^https?:$/.test( link.protocol ) && link.hostname && link.hostname !== window.location.hostname ) {
link.target = '_blank';
if ( ! /\bnoopener\b/.test( link.rel ) ) {
link.rel = ( link.rel + ' noopener' ).trim();
}
}
} );
In these packs
- Content and media: Shortcodes, links, images and small design touches for the public site.