Skip to content

Instantly share code, notes, and snippets.

@mishterk
Last active June 3, 2022 20:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mishterk/5cb2ecd614d1eb6b60278e8e12e7475a to your computer and use it in GitHub Desktop.
Save mishterk/5cb2ecd614d1eb6b60278e8e12e7475a to your computer and use it in GitHub Desktop.
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