Summery Summery
Outputs the content for the current Navigation Menu widget instance.
Syntax Syntax
Parameters Parameters
- $args
-
(Required) Display arguments including 'before_title', 'after_title', 'before_widget', and 'after_widget'.
- $instance
-
(Required) Settings for the current Navigation Menu widget instance.
Source Source
File: wp-includes/widgets/class-wp-nav-menu-widget.php
public function widget( $args, $instance ) { // Get menu. $nav_menu = ! empty( $instance['nav_menu'] ) ? wp_get_nav_menu_object( $instance['nav_menu'] ) : false; if ( ! $nav_menu ) { return; } $default_title = __( 'Menu' ); $title = ! empty( $instance['title'] ) ? $instance['title'] : ''; /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */ $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); echo $args['before_widget']; if ( $title ) { echo $args['before_title'] . $title . $args['after_title']; } $format = current_theme_supports( 'html5', 'navigation-widgets' ) ? 'html5' : 'xhtml'; /** * Filters the HTML format of widgets with navigation links. * * @since 5.5.0 * * @param string $format The type of markup to use in widgets with navigation links. * Accepts 'html5', 'xhtml'. */ $format = apply_filters( 'navigation_widgets_format', $format ); if ( 'html5' === $format ) { // The title may be filtered: Strip out HTML and make sure the aria-label is never empty. $title = trim( strip_tags( $title ) ); $aria_label = $title ? $title : $default_title; $nav_menu_args = array( 'fallback_cb' => '', 'menu' => $nav_menu, 'container' => 'nav', 'container_aria_label' => $aria_label, 'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>', );
Advertisement
Changelog Changelog
Version | Description |
---|---|
3.0.0 | Introduced. |