wp_nav_menu_taxonomy_meta_boxes()WP 3.0.0

Creates a meta box for any taxonomy in an accordion on the menu creation page.

Works based on the function get_taxonomies() with the parameter 'show_in_nav_menus' => true.

The function is used by the engine and is generally not intended for use elsewhere.

To display similar meta boxes for post types, the function wp_nav_menu_post_type_meta_boxes() is used.

Each obtained taxonomy object is passed through the hook-filter nav_menu_meta_box_object, where you can change, for example, the title of the meta box or completely cancel its output in the accordion.

The meta box is added by the function add_meta_box() in the following template:

add_meta_box( "add-{$id}", $tax->labels->name, 'wp_nav_menu_item_taxonomy_meta_box', 'nav-menus', 'side', 'default', $tax );

Where:

  • $tax - taxonomy object.
  • $tax->labels->name - title of the taxonomy, for example Categories, Tags, and so on.
  • $id = $tax->name - name of the taxonomy, for example category, post_tag, and so on.
Hooks from the function

Returns

null. Nothing (null).

Usage

wp_nav_menu_taxonomy_meta_boxes();

Examples

0

#1 Used in the WP core

See the file /wp-admin/nav-menus.php for an example of how to use it.

Changelog

Since 3.0.0 Introduced.

wp_nav_menu_taxonomy_meta_boxes() code WP 6.9.1

function wp_nav_menu_taxonomy_meta_boxes() {
	$taxonomies = get_taxonomies( array( 'show_in_nav_menus' => true ), 'object' );

	if ( ! $taxonomies ) {
		return;
	}

	foreach ( $taxonomies as $tax ) {
		/** This filter is documented in wp-admin/includes/nav-menu.php */
		$tax = apply_filters( 'nav_menu_meta_box_object', $tax );

		if ( $tax ) {
			$id = $tax->name;
			add_meta_box(
				"add-{$id}",
				$tax->labels->name,
				'wp_nav_menu_item_taxonomy_meta_box',
				'nav-menus',
				'side',
				'default',
				$tax
			);
		}
	}
}