I had some issues recently where I was trying to edit a client website to have custom options page and sub options pages using the Wordpress plugin Advanced Custom Fields (ACF). According to their documentation, it's very simple to do.
But I ran into 2 silly problems that I didn't account for. If you're not able to get the provided code to work, here are the 2 reasons why it didn't work for me:
- You have to have the Pro version of the plugin
- There can only be 1 options page - the theme already had one that I didn't know about
If you're not sure if your website already has an options page, do a search all files on the function 'acf_add_options_page'
Otherwise, here is a code example to get this working with a main options page and a sub page:
if( function_exists('acf_add_options_page') ) {
$parent = acf_add_options_page(array(
'page_title' => 'Theme General Settings',
'menu_title' => 'Theme Settings',
'menu_slug' => 'theme-general-settings',
'capability' => 'edit_posts',
'redirect' => false
));
acf_add_options_sub_page(array(
'page_title' => 'Subpage',
'menu_title' => 'Subpage',
'parent_slug' => $parent['menu_slug'],
));
}
In the code above, acf_add_options_sub_page()
function is used to create a subpage. This function takes an array of arguments similar to acf_add_options_page()
. The key difference is that it includes a 'parent_slug'
parameter. The 'parent_slug'
parameter refers to the slug of the parent options page.