Skip to content

Instantly share code, notes, and snippets.

@nunof07

nunof07/functions.php

Last active Apr 12, 2019
Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

@nunof07 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