Last active
June 3, 2022 20:33
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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', | |
] ); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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