Add an ACF Site Settings Options Page
Registers a "Site Settings" options page with Header and Footer sub-pages in the admin, ready for ACF field groups that hold site-wide values.
Opens WPIDE on
Code
add_action( 'acf/init', function () {
if ( ! function_exists( 'acf_add_options_page' ) ) {
return;
}
acf_add_options_page( array(
'page_title' => 'Site Settings',
'menu_title' => 'Site Settings',
'menu_slug' => 'site-settings',
'capability' => 'edit_theme_options',
'icon_url' => 'dashicons-admin-generic',
'position' => 61,
'redirect' => false,
) );
foreach ( array( 'Header', 'Footer' ) as $section ) {
acf_add_options_sub_page( array(
'page_title' => $section . ' Settings',
'menu_title' => $section,
'parent_slug' => 'site-settings',
'capability' => 'edit_theme_options',
) );
}
} );
Notes
Options pages need ACF PRO. Assign field groups with the rule "Options Page is equal to Site Settings" and read values with get_field( 'name', 'option' ).
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.