Skip to content

Instantly share code, notes, and snippets.

@nunof07
Last active April 12, 2019 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nunof07/39b30606be889a8596736416692b7094 to your computer and use it in GitHub Desktop.
Save nunof07/39b30606be889a8596736416692b7094 to your computer and use it in GitHub Desktop.
Add ACF option pages
<?php
/**
* Unique identifier for the theme. Used for the text domain and other stuff.
*
* @return string
*/
function theme_key() {
return 'yourthemeid';
}
/**
* Add option pages.
*/
add_action('acf/init', function () {
if (!function_exists('acf_add_options_page')) {
return;
}
acf_add_options_page(array(
'page_title' => __('Theme Settings', theme_key()),
'menu_title' => __('Settings', theme_key()),
'menu_slug' => theme_key() . '-settings',
));
$sub_pages = [
// [
// 'page_title' => 'Header Settings',
// 'menu_title' => 'Header',
// ],
];
foreach ($sub_pages as $page) {
acf_add_options_sub_page([
'page_title' => __($page['page_title'], theme_key()),
'menu_title' => __($page['menu_title'], theme_key()),
'parent_slug' => theme_key() . '-settings',
]);
}
});
@nunof07
Copy link
Author

nunof07 commented Apr 5, 2019

Update the theme_key(). Add sub-pages as needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment