add_theme_page

Home » Functions » add_theme_page

If you’re working with WordPress theme development, the add_theme_page() function is one that you’ll likely use often. This function allows you to add a new page to the WordPress admin area under the "Appearance" menu.

The add_theme_page() function takes four parameters:

  1. $page_title: The title that will appear at the top of the page in the WordPress admin area.
  2. $menu_title: The title that will appear in the WordPress admin menu.
  3. $capability: The user role that is required to view and access the new page.
  4. $menu_slug: The unique slug that will be used to identify this new page.

Here’s an example of how you would use the add_theme_page() function to add a new page to the WordPress admin:

function my_theme_options_page() {
  // Add a new page under Appearance
  add_theme_page( 'My Theme Options', 'Theme Options', 'manage_options', 'my-theme-options', 'my_theme_options_callback' );
}

function my_theme_options_callback() {
  // Output the contents of the new page
  echo '<div class="wrap"><h1>My Theme Options</h1><p>Welcome to my theme options page!</p></div>';
}

// Add the new page to the admin menu
add_action( 'admin_menu', 'my_theme_options_page' );

In this example, we’re adding a new page to the "Appearance" menu with the title "Theme Options". We’re requiring the "manage_options" capability to access this page, which means that only users with the "Administrator" role will be able to see it. The unique slug we’ve chosen for this page is "my-theme-options". Finally, we’ve defined a callback function that will output the contents of the new page.

Once you’ve added the new page to the WordPress admin menu, users with the appropriate role will be able to access it and see the content you’ve defined in your callback function. The add_theme_page() function is a powerful tool for customizing the WordPress admin area and providing extra functionality to your theme.

Learn More on WordPress.org

WordPress snippets using the add_theme_page function

Register an account to save your snippets or go Pro to get more features.