Streaming live at 10am (PST)

Adding noopener to all external links

Hey guys

Is there some custom code I can add to make all external links on my site “noopener” or “noreferrer”?
As per recommendations from Google Lighthouse

To be clear, this is for all pages of our blog, not just static pages. So I’m guessing would require custom code.

Be great to hear people’s thoughts! :slight_smile:

Here is my site Read-Only: LINK
(how to share your site Read-Only link)

@williamsbrad1994 found this on stackoverflow. This should work well, just change the re variable to your domain name in the same format.

function setRelAttribute() {
    var elems = document.body.getElementsByTagName('a');
    for (var i = 0; i < elems.length; i++) {
        var elem = elems[i]
        var re = /
        var isInternal = re.test(elem.href)
        if (!isInternal) {
            elem.rel= 'noopener noreferrer nofollow'

document.addEventListener('DOMContentLoaded', function () {
}, false);

Thanks for this! Worked right away (I also deleted the ‘nofollow’ tag)