cafe_add_settings_page()
Purpose
Adds a Settings Page (for example "Contact Settings" or "Theme Options") to the
WordPress admin menu from PHP. Field groups placed on it save site-wide
values that you read anywhere with cafe_get_option().
You can also create Settings Pages without code in CAFE → Settings Pages. See the Settings Pages guide.
Syntax
cafe_add_settings_page( array $args ): bool
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$args['title'] |
string | Required | Page heading, up to 100 characters. |
$args['slug'] |
string | from the title | Page address (admin.php?page=…): 2-63 lowercase letters, digits or dashes. Cannot start with cafe-. |
$args['menu_title'] |
string | the title | Menu label, up to 60 characters. |
$args['parent_menu'] |
string | 'top' |
'top' for its own menu item, a WordPress menu ('options-general.php', 'themes.php', 'tools.php', 'index.php', 'edit.php', 'edit.php?post_type=page', 'upload.php', 'plugins.php', 'users.php') or the slug of a top-level Settings Page. |
$args['icon'] |
string | CAFE icon | A Dashicon class such as 'dashicons-phone' (top-level pages only). |
$args['position'] |
int|null | null |
Menu position for top-level pages (0-9999). |
$args['capability'] |
string | 'manage_options' |
Who can open and save the page: 'manage_options', 'edit_theme_options', 'edit_others_posts' or 'publish_posts'. |
$args['description'] |
string | '' |
Text under the heading, up to 500 characters. |
$args['save_label'] |
string | 'Save Changes' |
Save button label, up to 40 characters. |
Return value
true when the page was added. false when an argument is invalid; WordPress
then reports the reason as a "doing it wrong" notice (visible with WP_DEBUG).
Example
add_action( 'cafe_init', function () {
cafe_add_settings_page(
[
'title' => 'Contact Settings',
'menu_title' => 'Contact',
'parent_menu' => 'options-general.php',
'description' => 'Phone, email and address shown in the header and footer.',
]
);
} );
// Then, in a field group: Location → Settings Page is "Contact Settings".
// In your theme:
echo esc_html( cafe_get_option( 'phone' ) );
Notes
- Call it on
initorcafe_init, before WordPress builds the admin menu. - Pages from code appear in CAFE → Settings Pages marked "Registered in PHP" and cannot be edited or deleted there. A code page wins over an admin page with the same slug.
- Values belong to the fields, not to the page: removing the page keeps them.
- All Settings Pages share one site-wide scope, so give option fields unique names
(for example
footer_text,contact_phone).