endurain
10/4/2019 - 4:48 AM

Register Options page & Add Custom Sub-Sections

Use to create an custom options page for ACF fields to live. For example, the code below creates a Theme options page for acf fields to config header and footer settings. Place in theme's functions.php

NOTE: ACF PRO MUST BE INSTALLED FOR THIS TO WORK

//////////////////////////////////////////////////////////////////
// ACF Custom Functions
//////////////////////////////////////////////////////////////////

//Register Options page & Add Custom Sub-Sections
add_action('admin_menu', 'add_options_pages');
function add_options_pages() {
  if (!function_exists('acf_add_options_page')) {
    return;
  }
  acf_add_options_page(array('page_title' => 'Theme Options'));
  // the following parent url will be auto generated by the above call
  // you can change the slug by specifying a slug for the page
  $parent = 'acf-options-theme-options';
  $sub_options_pages = array('Global Styles', 'Header', 'Sidebar', 'Footer');
  foreach ($sub_options_pages as $title) {
    acf_add_options_sub_page(array(
    	'title' => $title,
    	'parent' => $parent
    ));
  }
}