63 /** |
66 /** |
64 * Filters the CSS class(es) applied to a menu list element. |
67 * Filters the CSS class(es) applied to a menu list element. |
65 * |
68 * |
66 * @since 4.8.0 |
69 * @since 4.8.0 |
67 * |
70 * |
68 * @param array $classes The CSS classes that are applied to the menu `<ul>` element. |
71 * @param string[] $classes Array of the CSS classes that are applied to the menu `<ul>` element. |
69 * @param stdClass $args An object of `wp_nav_menu()` arguments. |
72 * @param stdClass $args An object of `wp_nav_menu()` arguments. |
70 * @param int $depth Depth of menu item. Used for padding. |
73 * @param int $depth Depth of menu item. Used for padding. |
71 */ |
74 */ |
72 $class_names = join( ' ', apply_filters( 'nav_menu_submenu_css_class', $classes, $args, $depth ) ); |
75 $class_names = join( ' ', apply_filters( 'nav_menu_submenu_css_class', $classes, $args, $depth ) ); |
73 $class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : ''; |
76 $class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : ''; |
135 * @param int $depth Depth of menu item. Used for padding. |
138 * @param int $depth Depth of menu item. Used for padding. |
136 */ |
139 */ |
137 $args = apply_filters( 'nav_menu_item_args', $args, $item, $depth ); |
140 $args = apply_filters( 'nav_menu_item_args', $args, $item, $depth ); |
138 |
141 |
139 /** |
142 /** |
140 * Filters the CSS class(es) applied to a menu item's list item element. |
143 * Filters the CSS classes applied to a menu item's list item element. |
141 * |
144 * |
142 * @since 3.0.0 |
145 * @since 3.0.0 |
143 * @since 4.1.0 The `$depth` parameter was added. |
146 * @since 4.1.0 The `$depth` parameter was added. |
144 * |
147 * |
145 * @param array $classes The CSS classes that are applied to the menu item's `<li>` element. |
148 * @param string[] $classes Array of the CSS classes that are applied to the menu item's `<li>` element. |
146 * @param WP_Post $item The current menu item. |
149 * @param WP_Post $item The current menu item. |
147 * @param stdClass $args An object of wp_nav_menu() arguments. |
150 * @param stdClass $args An object of wp_nav_menu() arguments. |
148 * @param int $depth Depth of menu item. Used for padding. |
151 * @param int $depth Depth of menu item. Used for padding. |
149 */ |
152 */ |
150 $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args, $depth ) ); |
153 $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args, $depth ) ); |
159 * @param string $menu_id The ID that is applied to the menu item's `<li>` element. |
162 * @param string $menu_id The ID that is applied to the menu item's `<li>` element. |
160 * @param WP_Post $item The current menu item. |
163 * @param WP_Post $item The current menu item. |
161 * @param stdClass $args An object of wp_nav_menu() arguments. |
164 * @param stdClass $args An object of wp_nav_menu() arguments. |
162 * @param int $depth Depth of menu item. Used for padding. |
165 * @param int $depth Depth of menu item. Used for padding. |
163 */ |
166 */ |
164 $id = apply_filters( 'nav_menu_item_id', 'menu-item-'. $item->ID, $item, $args, $depth ); |
167 $id = apply_filters( 'nav_menu_item_id', 'menu-item-' . $item->ID, $item, $args, $depth ); |
165 $id = $id ? ' id="' . esc_attr( $id ) . '"' : ''; |
168 $id = $id ? ' id="' . esc_attr( $id ) . '"' : ''; |
166 |
169 |
167 $output .= $indent . '<li' . $id . $class_names .'>'; |
170 $output .= $indent . '<li' . $id . $class_names . '>'; |
168 |
171 |
169 $atts = array(); |
172 $atts = array(); |
170 $atts['title'] = ! empty( $item->attr_title ) ? $item->attr_title : ''; |
173 $atts['title'] = ! empty( $item->attr_title ) ? $item->attr_title : ''; |
171 $atts['target'] = ! empty( $item->target ) ? $item->target : ''; |
174 $atts['target'] = ! empty( $item->target ) ? $item->target : ''; |
172 $atts['rel'] = ! empty( $item->xfn ) ? $item->xfn : ''; |
175 if ( '_blank' === $item->target && empty( $item->xfn ) ) { |
173 $atts['href'] = ! empty( $item->url ) ? $item->url : ''; |
176 $atts['rel'] = 'noopener noreferrer'; |
|
177 } else { |
|
178 $atts['rel'] = $item->xfn; |
|
179 } |
|
180 $atts['href'] = ! empty( $item->url ) ? $item->url : ''; |
|
181 $atts['aria-current'] = $item->current ? 'page' : ''; |
174 |
182 |
175 /** |
183 /** |
176 * Filters the HTML attributes applied to a menu item's anchor element. |
184 * Filters the HTML attributes applied to a menu item's anchor element. |
177 * |
185 * |
178 * @since 3.6.0 |
186 * @since 3.6.0 |
179 * @since 4.1.0 The `$depth` parameter was added. |
187 * @since 4.1.0 The `$depth` parameter was added. |
180 * |
188 * |
181 * @param array $atts { |
189 * @param array $atts { |
182 * The HTML attributes applied to the menu item's `<a>` element, empty strings are ignored. |
190 * The HTML attributes applied to the menu item's `<a>` element, empty strings are ignored. |
183 * |
191 * |
184 * @type string $title Title attribute. |
192 * @type string $title Title attribute. |
185 * @type string $target Target attribute. |
193 * @type string $target Target attribute. |
186 * @type string $rel The rel attribute. |
194 * @type string $rel The rel attribute. |
187 * @type string $href The href attribute. |
195 * @type string $href The href attribute. |
|
196 * @type string $aria_current The aria-current attribute. |
188 * } |
197 * } |
189 * @param WP_Post $item The current menu item. |
198 * @param WP_Post $item The current menu item. |
190 * @param stdClass $args An object of wp_nav_menu() arguments. |
199 * @param stdClass $args An object of wp_nav_menu() arguments. |
191 * @param int $depth Depth of menu item. Used for padding. |
200 * @param int $depth Depth of menu item. Used for padding. |
192 */ |
201 */ |
193 $atts = apply_filters( 'nav_menu_link_attributes', $atts, $item, $args, $depth ); |
202 $atts = apply_filters( 'nav_menu_link_attributes', $atts, $item, $args, $depth ); |
194 |
203 |
195 $attributes = ''; |
204 $attributes = ''; |
196 foreach ( $atts as $attr => $value ) { |
205 foreach ( $atts as $attr => $value ) { |
197 if ( ! empty( $value ) ) { |
206 if ( ! empty( $value ) ) { |
198 $value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value ); |
207 $value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value ); |
199 $attributes .= ' ' . $attr . '="' . $value . '"'; |
208 $attributes .= ' ' . $attr . '="' . $value . '"'; |
200 } |
209 } |
201 } |
210 } |
202 |
211 |
203 /** This filter is documented in wp-includes/post-template.php */ |
212 /** This filter is documented in wp-includes/post-template.php */ |
213 * @param stdClass $args An object of wp_nav_menu() arguments. |
222 * @param stdClass $args An object of wp_nav_menu() arguments. |
214 * @param int $depth Depth of menu item. Used for padding. |
223 * @param int $depth Depth of menu item. Used for padding. |
215 */ |
224 */ |
216 $title = apply_filters( 'nav_menu_item_title', $title, $item, $args, $depth ); |
225 $title = apply_filters( 'nav_menu_item_title', $title, $item, $args, $depth ); |
217 |
226 |
218 $item_output = $args->before; |
227 $item_output = $args->before; |
219 $item_output .= '<a'. $attributes .'>'; |
228 $item_output .= '<a' . $attributes . '>'; |
220 $item_output .= $args->link_before . $title . $args->link_after; |
229 $item_output .= $args->link_before . $title . $args->link_after; |
221 $item_output .= '</a>'; |
230 $item_output .= '</a>'; |
222 $item_output .= $args->after; |
231 $item_output .= $args->after; |
223 |
232 |
224 /** |
233 /** |