From 36957aaee9922133fddcd8b12b06f341918b16d8 Mon Sep 17 00:00:00 2001 From: Kevin Date: Wed, 6 Oct 2021 14:04:41 +0200 Subject: [PATCH] Adds rel noopener to external links --- wp_bem_menu.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/wp_bem_menu.php b/wp_bem_menu.php index 6d2dd583..17ca09bc 100644 --- a/wp_bem_menu.php +++ b/wp_bem_menu.php @@ -128,6 +128,11 @@ public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 $attributes .= ! empty( $item->xfn ) ? ' rel="' . esc_attr( $item->xfn ) . '"' : ''; $attributes .= ! empty( $item->url ) ? ' href="' . esc_attr( $item->url ) . '"' : ''; + // Add 'noopener' to external links without a set xfn + if ( empty( $item->xfn ) && ! empty( $item->target ) ) { + $attributes .= " rel='noopener'"; + } + $attributes = apply_filters( 'bem_menu_link_attributes', $attributes, $item ); // Create link markup