@@ -248,61 +248,98 @@ public function start_el( &$output, $data_object, $depth = 0, $args = null, $cur
248248 */
249249 $ title = apply_filters ( 'nav_menu_item_title ' , $ title , $ menu_item , $ args , $ depth );
250250
251- $ atts = array ();
252- $ atts ['target ' ] = ! empty ( $ menu_item ->target ) ? $ menu_item ->target : '' ;
253- $ atts ['rel ' ] = ! empty ( $ menu_item ->xfn ) ? $ menu_item ->xfn : '' ;
251+ if ( 'placeholder ' === $ menu_item ->type ) {
252+ /*
253+ * Placeholder items render as a non-interactive `<span>` rather than an `<a>`.
254+ * Because most themes style nav links via selectors like `> a`, the `<span>`
255+ * will not automatically inherit those styles. Themes that wish to display
256+ * placeholders consistently with their other nav items should target the
257+ * `menu-item-type-placeholder` class that is added to the parent `<li>`:
258+ *
259+ * .menu-item-type-placeholder > span {
260+ * display: block;
261+ * cursor: default;
262+ * }
263+ *
264+ * Use the `nav_menu_placeholder_attributes` filter to add custom attributes
265+ * or classes directly to the `<span>` element.
266+ */
267+
268+ /**
269+ * Filters the HTML attributes applied to a placeholder menu item's span element.
270+ *
271+ * @since x.x.x
272+ *
273+ * @param array $atts The HTML attributes applied to the span element, empty strings are ignored.
274+ * @param WP_Post $menu_item The current menu item object.
275+ * @param stdClass $args An object of wp_nav_menu() arguments.
276+ * @param int $depth Depth of menu item. Used for padding.
277+ */
278+ $ span_atts = apply_filters ( 'nav_menu_placeholder_attributes ' , array (), $ menu_item , $ args , $ depth );
279+ $ attributes = $ this ->build_atts ( $ span_atts );
280+
281+ $ item_output = $ args ->before ;
282+ $ item_output .= '<span ' . $ attributes . '> ' ;
283+ $ item_output .= $ args ->link_before . $ title . $ args ->link_after ;
284+ $ item_output .= '</span> ' ;
285+ $ item_output .= $ args ->after ;
286+ } else {
287+ $ atts = array ();
288+ $ atts ['target ' ] = ! empty ( $ menu_item ->target ) ? $ menu_item ->target : '' ;
289+ $ atts ['rel ' ] = ! empty ( $ menu_item ->xfn ) ? $ menu_item ->xfn : '' ;
290+
291+ if ( ! empty ( $ menu_item ->url ) ) {
292+ if ( $ this ->privacy_policy_url === $ menu_item ->url ) {
293+ $ atts ['rel ' ] = empty ( $ atts ['rel ' ] ) ? 'privacy-policy ' : $ atts ['rel ' ] . ' privacy-policy ' ;
294+ }
295+
296+ $ atts ['href ' ] = $ menu_item ->url ;
297+ } else {
298+ $ atts ['href ' ] = '' ;
299+ }
254300
255- if ( ! empty ( $ menu_item ->url ) ) {
256- if ( $ this ->privacy_policy_url === $ menu_item ->url ) {
257- $ atts ['rel ' ] = empty ( $ atts ['rel ' ] ) ? 'privacy-policy ' : $ atts ['rel ' ] . ' privacy-policy ' ;
301+ $ atts ['aria-current ' ] = $ menu_item ->current ? 'page ' : '' ;
302+
303+ // Add title attribute only if it does not match the link text (before or after filtering).
304+ if ( ! empty ( $ menu_item ->attr_title )
305+ && trim ( strtolower ( $ menu_item ->attr_title ) ) !== trim ( strtolower ( $ menu_item ->title ) )
306+ && trim ( strtolower ( $ menu_item ->attr_title ) ) !== trim ( strtolower ( $ the_title_filtered ) )
307+ && trim ( strtolower ( $ menu_item ->attr_title ) ) !== trim ( strtolower ( $ title ) )
308+ ) {
309+ $ atts ['title ' ] = $ menu_item ->attr_title ;
310+ } else {
311+ $ atts ['title ' ] = '' ;
258312 }
259313
260- $ atts ['href ' ] = $ menu_item ->url ;
261- } else {
262- $ atts ['href ' ] = '' ;
314+ /**
315+ * Filters the HTML attributes applied to a menu item's anchor element.
316+ *
317+ * @since 3.6.0
318+ * @since 4.1.0 The `$depth` parameter was added.
319+ *
320+ * @param array $atts {
321+ * The HTML attributes applied to the menu item's `<a>` element, empty strings are ignored.
322+ *
323+ * @type string $title Title attribute.
324+ * @type string $target Target attribute.
325+ * @type string $rel The rel attribute.
326+ * @type string $href The href attribute.
327+ * @type string $aria-current The aria-current attribute.
328+ * }
329+ * @param WP_Post $menu_item The current menu item object.
330+ * @param stdClass $args An object of wp_nav_menu() arguments.
331+ * @param int $depth Depth of menu item. Used for padding.
332+ */
333+ $ atts = apply_filters ( 'nav_menu_link_attributes ' , $ atts , $ menu_item , $ args , $ depth );
334+ $ attributes = $ this ->build_atts ( $ atts );
335+
336+ $ item_output = $ args ->before ;
337+ $ item_output .= '<a ' . $ attributes . '> ' ;
338+ $ item_output .= $ args ->link_before . $ title . $ args ->link_after ;
339+ $ item_output .= '</a> ' ;
340+ $ item_output .= $ args ->after ;
263341 }
264342
265- $ atts ['aria-current ' ] = $ menu_item ->current ? 'page ' : '' ;
266-
267- // Add title attribute only if it does not match the link text (before or after filtering).
268- if ( ! empty ( $ menu_item ->attr_title )
269- && trim ( strtolower ( $ menu_item ->attr_title ) ) !== trim ( strtolower ( $ menu_item ->title ) )
270- && trim ( strtolower ( $ menu_item ->attr_title ) ) !== trim ( strtolower ( $ the_title_filtered ) )
271- && trim ( strtolower ( $ menu_item ->attr_title ) ) !== trim ( strtolower ( $ title ) )
272- ) {
273- $ atts ['title ' ] = $ menu_item ->attr_title ;
274- } else {
275- $ atts ['title ' ] = '' ;
276- }
277-
278- /**
279- * Filters the HTML attributes applied to a menu item's anchor element.
280- *
281- * @since 3.6.0
282- * @since 4.1.0 The `$depth` parameter was added.
283- *
284- * @param array $atts {
285- * The HTML attributes applied to the menu item's `<a>` element, empty strings are ignored.
286- *
287- * @type string $title Title attribute.
288- * @type string $target Target attribute.
289- * @type string $rel The rel attribute.
290- * @type string $href The href attribute.
291- * @type string $aria-current The aria-current attribute.
292- * }
293- * @param WP_Post $menu_item The current menu item object.
294- * @param stdClass $args An object of wp_nav_menu() arguments.
295- * @param int $depth Depth of menu item. Used for padding.
296- */
297- $ atts = apply_filters ( 'nav_menu_link_attributes ' , $ atts , $ menu_item , $ args , $ depth );
298- $ attributes = $ this ->build_atts ( $ atts );
299-
300- $ item_output = $ args ->before ;
301- $ item_output .= '<a ' . $ attributes . '> ' ;
302- $ item_output .= $ args ->link_before . $ title . $ args ->link_after ;
303- $ item_output .= '</a> ' ;
304- $ item_output .= $ args ->after ;
305-
306343 /**
307344 * Filters a menu item's starting output.
308345 *
0 commit comments