How can I create a settings page for my custom plugin?
Asked on Sep 27, 2025
Answer
Creating a settings page for your custom plugin involves using the WordPress Settings API to add a new menu item and page in the WordPress admin area. This allows users to configure your plugin's options directly from the dashboard.
<!-- BEGIN COPY / PASTE -->
add_action('admin_menu', 'my_plugin_create_menu');
function my_plugin_create_menu() {
add_menu_page(
'My Plugin Settings', // Page title
'My Plugin', // Menu title
'manage_options', // Capability
'my-plugin-settings', // Menu slug
'my_plugin_settings_page' // Callback function
);
}
function my_plugin_settings_page() {
echo '<div class="wrap">';
echo '<h1>My Plugin Settings</h1>';
echo '<form method="post" action="options.php">';
settings_fields('my_plugin_options_group');
do_settings_sections('my-plugin-settings');
submit_button();
echo '</form>';
echo '</div>';
}
<!-- END COPY / PASTE -->Additional Comment:
- Use "add_menu_page" to create a top-level admin menu item for your plugin.
- Ensure that the user has the "manage_options" capability to access the settings page.
- Use "settings_fields" and "do_settings_sections" to include your plugin's settings fields.
- Register your settings and fields using the WordPress Settings API for better integration.
Recommended Links: