Make WordPress Core

Changeset 45141


Ignore:
Timestamp:
04/08/2019 11:05:22 PM (6 years ago)
Author:
pento
Message:

Menus: Add rel="noopener" to target="_blank" links by default in menus.

This expands upon rel="noopener" being previously added to links in the content.

Props audrasjb, welcher.
Fixes #43290.

Location:
trunk
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-walker-nav-menu.php

    r42877 r45141  
    170170        $output .= $indent . '<li' . $id . $class_names . '>';
    171171
    172         $atts                 = array();
    173         $atts['title']        = ! empty( $item->attr_title ) ? $item->attr_title : '';
    174         $atts['target']       = ! empty( $item->target ) ? $item->target : '';
    175         $atts['rel']          = ! empty( $item->xfn ) ? $item->xfn : '';
     172        $atts           = array();
     173        $atts['title']  = ! empty( $item->attr_title ) ? $item->attr_title : '';
     174        $atts['target'] = ! empty( $item->target ) ? $item->target : '';
     175        if ( '_blank' === $item->target && empty( $item->xfn ) ) {
     176            $atts['rel'] = 'noopener noreferrer';
     177        } else {
     178            $atts['rel'] = $item->xfn;
     179        }
    176180        $atts['href']         = ! empty( $item->url ) ? $item->url : '';
    177181        $atts['aria-current'] = $item->current ? 'page' : '';
Note: See TracChangeset for help on using the changeset viewer.