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:\xampp\htdocs\wp-content\plugins\acf-options-page\acf-options-page.php on line 230
Warning: Illegal string offset 'title' in C:\xampp\htdocs\wp-content\plugins\acf-options-page\acf-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:
// Add Options Page
function add_my_options_page() {
if( function_exists('acf_add_options_page') ) {
acf_add_options_page();
}
}
add_action( 'plugins_loaded', 'add_my_options_page' );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With