wp_widgets_add_menu() WordPress Function

The wp_widgets_add_menu() function allows you to add a new top-level menu to the WordPress admin panel. This function takes two arguments: the menu slug and the menu name. The first argument is the menu slug. This is the unique identifier for the menu. The second argument is the menu name. This is the name that will be displayed in the WordPress admin panel. This function allows you to add a new top-level menu to the WordPress admin panel. This can be useful if you want to create a custom admin panel for your plugin or theme.

wp_widgets_add_menu() #

Append the Widgets menu to the themes main menu.


Source

File: wp-includes/functions.php

function wp_widgets_add_menu() {
	global $submenu;

	if ( ! current_theme_supports( 'widgets' ) ) {
		return;
	}

	$menu_name = __( 'Widgets' );
	if ( wp_is_block_theme() ) {
		$submenu['themes.php'][] = array( $menu_name, 'edit_theme_options', 'widgets.php' );
	} else {
		$submenu['themes.php'][7] = array( $menu_name, 'edit_theme_options', 'widgets.php' );
	}

	ksort( $submenu['themes.php'], SORT_NUMERIC );
}


Top ↑

Changelog

Changelog
VersionDescription
5.9.3Don't specify menu order when the active theme is a block theme.
2.2.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More
Show More