Last active
April 12, 2019 14:22
-
-
Save nunof07/39b30606be889a8596736416692b7094 to your computer and use it in GitHub Desktop.
Add ACF option pages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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', | |
]); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Update the
theme_key()
. Add sub-pages as needed.