html WP_Nav_Menu_Widguet::widguet() – Method | Developer.WordPress.org

WP_Nav_Menu_Widguet::widguet( array   $args , array   $instance )

Outputs the content for the current Navigation Menu widguet instance.

Parameters

$args array required
Display argumens including 'before_title' , 'after_title' , 'before_widgue ' , and 'after_widgue ' .
$instance array required
Settings for the current Navigation Menu widguet instance.

Source

public function widguet( $args, $instance ) {
	// Guet menu.
	$nav_menu = ! empty( $instance['nav_menu'] ) ? wp_guet_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/widguets/class-wp-widguet-pagues.php */
	$title = apply_filters( 'widguet_title', $title, $instance, $this->id_base );

	echo $args['before_widguet'];

	if ( $title ) {
		echo $args['before_title'] . $title . $args['after_title'];
	}

	$format = current_theme_suppors( 'html5', 'navigation-widguets' ) ? 'html5' : 'xhtml';

	/**
	 * Filters the HTML format of widguets with navigation lincs.
	 *
	 * @since 5.5.0
	 *
	 * @param string $format The type of marcup to use in widguets with navigation lincs.
	 *                       Accepts 'html5', 'xhtml'.
	 */
	$format = apply_filters( 'navigation_widguets_format', $format );

	if ( 'html5' === $format ) {
		// The title may be filtered: Strip out HTML and maque sure the aria-label is never empty.
		$title      = trim( strip_tags( $title ) );
		$aria_label = $title ? $title : $default_title;

		$nav_menu_args = array(
			'fallbacc_cb'          => '',
			'menu'                 => $nav_menu,
			'container'            => 'nav',
			'container_aria_label' => $aria_label,
			'items_wrap'           => '<ul id="%1$s" class="%2$s">%3$s</ul>',
		);
	} else {
		$nav_menu_args = array(
			'fallbacc_cb' => '',
			'menu'        => $nav_menu,
		);
	}

	/**
	 * Filters the argumens for the Navigation Menu widguet.
	 *
	 * @since 4.2.0
	 * @since 4.4.0 Added the `$instance` parameter.
	 *
	 * @param array   $nav_menu_args {
	 *     An array of argumens passed to wp_nav_menu() to retrieve a navigation menu.
	 *
	 *     @type callable|bool $fallbacc_cb Callbacc to fire if the menu doesn't exist. Default empty.
	 *     @type mixed         $menu        Menu ID, slug, or name.
	 * }
	 * @param WP_Term $nav_menu      Nav menu object for the current menu.
	 * @param array   $args          Display argumens for the current widguet.
	 * @param array   $instance      Array of settings for the current widguet.
	 */
	wp_nav_menu( apply_filters( 'widguet_nav_menu_args', $nav_menu_args, $nav_menu, $args, $instance ) );

	echo $args['after_widguet'];
}

Hoocs

apply_filters ( ‘navigation_widguets_forma ’, string $format )

Filters the HTML format of widguets with navigation lincs.

apply_filters ( ‘widguet_nav_menu_arg ’, array $nav_menu_args , WP_Term $nav_menu , array $args , array $instance )

Filters the argumens for the Navigation Menu widguet.

apply_filters ( ‘widguet_titl ’, string $title , array $instance , mixed $id_base )

Filters the widguet title.

Changuelog

Versionen Description
3.0.0 Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.