I am trying to set up Options Page with Advanced Custom Fields in WP.
What I have in functions.php
file :
if( function_exists('acf_add_options_page') ) {
acf_add_options_page();
acf_add_options_sub_page('General');
acf_add_options_sub_page('Header');
acf_add_options_sub_page('Footer');
}
The problem is that function_exists('acf_add_options_page')
returns false
.
Seems like that function does not exist, however I am using the latest version of ACF.
When I try to use acf_add_options_page();
:
I get the following Uncaught Error: Call to undefined function acf_add_options_page()
When I avoid using acf_add_options_page();
, using only acf_add_options_sub_page()
:
I get the following Warning(s)
Warning: Illegal string offset 'slug' in C:xampphtdocswp-contentpluginsacf-options-pageacf-options-page.php on line 230
Warning: Illegal string offset 'title' in C:xampphtdocswp-contentpluginsacf-options-pageacf-options-page.php on line 230
p.s. I am using an hook (tried with init, plugins_loaded and admin_init) on functions.php
to load the functions :
add_action('init', 'my_init_function');
function my_init_function() {
if( function_exists('acf_add_options_page') ) {
acf_add_options_page();
acf_add_options_sub_page('General');
acf_add_options_sub_page('Header');
acf_add_options_sub_page('Footer');
}
}
I was having a similar issue, however I was running the code as part of a must-use plugin.
The issue there is that acf plugins are loaded after mu-plugins, so the function did not exist yet.
I used the
plugins_loaded
action to run it right after all the plugins were loaded.Here is my code:
Try without add_action. Just do:
Hi try this
$parent['menu_slug']
https://www.advancedcustomfields.com/resources/acf_add_options_sub_page/
Here is how i got it working: