Register multiple options pages

Last updated Mar 24, 2015

Overview

Multiple options pages can be registered by making use of the acf_add_options_page() and acf_add_options_sub_page() functions. Both functions can be used within the theme functions.php file.

Once registered, each options page will appear within the field group location rules making it quite easy to assign specific field groups to specific options pages.

Please note that for each options page, all values are saved and loaded using ‘option’ as the $post_id. This means that values are not saved to individual options pages, therefore, all fields require unique names to avoid data loss.

Requirements

To make use of the options page feature, you will need a copy of ACF PRO (ACF v5), or the options page add-on (ACF v4)

Examples

Basic

This example demonstrates how to create the default options page with 3 extra sub pages. By default the parent options page will redirect to the first child, however, this setting can be customized (please see following example).

functions.php

if( function_exists('acf_add_options_page') ) {
    
    acf_add_options_page();
    
    acf_add_options_sub_page('General');
    acf_add_options_sub_page('Header');
    acf_add_options_sub_page('Footer');
    
}

Advanced

This example demonstrates how to create a new parent options page with 2 extra sub pages. Please note the use of redirect => false which allows the parent to have it’s own page instead of redirecting to the first child.

functions.php

if( function_exists('acf_add_options_page') ) {
    
    acf_add_options_page(array(
        'page_title'    => 'Theme General Settings',
        'menu_title'    => 'Theme Settings',
        'menu_slug'     => 'theme-general-settings',
        'capability'    => 'edit_posts',
        'redirect'      => false
    ));
    
    acf_add_options_sub_page(array(
        'page_title'    => 'Theme Header Settings',
        'menu_title'    => 'Header',
        'parent_slug'   => 'theme-general-settings',
    ));
    
    acf_add_options_sub_page(array(
        'page_title'    => 'Theme Footer Settings',
        'menu_title'    => 'Footer',
        'parent_slug'   => 'theme-general-settings',
    ));
    
}

 

Related