Skip to content

Commit 3a1a9e0

Browse files
authored
Merge pull request #4 from level-level/feature/adds-noopener
Adds rel noopener to external links
2 parents e326068 + 36957aa commit 3a1a9e0

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

wp_bem_menu.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,11 @@ public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0
128128
$attributes .= ! empty( $item->xfn ) ? ' rel="' . esc_attr( $item->xfn ) . '"' : '';
129129
$attributes .= ! empty( $item->url ) ? ' href="' . esc_attr( $item->url ) . '"' : '';
130130

131+
// Add 'noopener' to external links without a set xfn
132+
if ( empty( $item->xfn ) && ! empty( $item->target ) ) {
133+
$attributes .= " rel='noopener'";
134+
}
135+
131136
$attributes = apply_filters( 'bem_menu_link_attributes', $attributes, $item );
132137

133138
// Create link markup

0 commit comments

Comments
 (0)