Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
How to register options pages in Advanced Custom Fields for WordPress (ACF). See https://www.awesomeacf.com/snippets/register-options-page/ for more details.
<?php
// register a top-level options page
if ( function_exists( 'acf_add_options_page' ) ) {
acf_add_options_page( [
'page_title' => 'My Options Page',
'menu_title' => 'My Options Page',
'menu_slug' => 'my-options-page',
'capability' => 'edit_posts',
'parent_slug' => '',
'position' => 3,
'icon_url' => false,
'redirect' => false,
'post_id' => 'options',
'autoload' => false,
'update_button' => 'Update',
] );
}
<?php
// register two sub-level options pages
if ( function_exists( 'acf_add_options_page' ) ) {
$parent = acf_add_options_page( [ …top level options here… ] );
acf_add_options_sub_page( [
'page_title' => 'My Sub Options Page',
'menu_title' => 'My Sub Options Page',
'parent_slug' => $parent['menu_slug'],
] );
acf_add_options_sub_page( [
'page_title' => 'My Second Sub Options Page',
'menu_title' => 'My Second Sub Options Page',
'parent_slug' => $parent['menu_slug'],
] );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.