fbpx
Use these snippets to register an ACF options pages

Register top-level ACF options page

Use this snippet to register a top-level menu item to house your custom fields as options.

<?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',
] );
}

Register sub-level options pages

If you need sub-pages, build on the previous snippet using the following example.

<?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'],
] );
}

These snippets can go in either a plugin or your theme’s functions.php file – whatever makes the most sense for your site.

Keep up to date with all things ACF!

Subscribe to our newsletter or follow @awesomeacf on Twitter!