add_theme_page()WP 2.0.0

Adds a submenu to the "Appearance" menu in the admin panel.

Note: the function should be hooked to admin_menu. If you get the error "You do not have sufficient permissions to access this page." it means you are calling the function too early.

No Hooks.

Returns

String|false. Returns "hook_suffix" of the inserted page (menu item). What the function add_submenu_page() returns.

Usage

add_theme_page( $page_title, $menu_title, $capability, $menu_slug, $callback, $position );
$page_title(string) (required)
Text of the <title> tag for the menu page when you are on it.
$menu_title(string) (required)
Text of the menu item.
$capability(string) (required)
User capability required to see this menu page.
$menu_slug(string) (required)
Menu identifier (slug) that can be used to access the menu. Must be unique.
$function(string/array)
Callback function that outputs the HTML code for the menu item page.
Default: ''
$position(number)
Position of the submenu item relative to other submenu items. Added in WP 5.3.0.
Default: null

Examples

0

#1 Creating the theme settings page

In this example, we will create our own item in the Appearance menu:

function my_appearance_menu_item() {
	add_theme_page('title page title', 'Menu item name', 'edit_theme_options', 'my-unique-identifier', 'my_plugin_function');
}
add_action('admin_menu', 'my_appearance_menu_item');

function my_plugin_function(){
	echo "The text on the page settings.";
}

Changelog

Since 2.0.0 Introduced.
Since 5.3.0 Added the $position parameter.

add_theme_page() code WP 7.0

function add_theme_page( $page_title, $menu_title, $capability, $menu_slug, $callback = '', $position = null ) {
	return add_submenu_page( 'themes.php', $page_title, $menu_title, $capability, $menu_slug, $callback, $position );
}