WP – Advanced Custom Fields : acf_add_options_page() does not exist

I am trying to set up Options Page with Advanced Custom Fields in WP.

What I have in functions.php file :

Read More
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');


    }

    }

Related posts

5 comments

  1. 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' );
    
  2. Try without add_action. Just do:

    if( function_exists('acf_add_options_page') ) {
    
    acf_add_options_page(array(
        'page_title'    => 'Theme Settings',
        'menu_title'    => 'Theme Settings',
        'menu_slug'     => 'theme-general-settings',
        'capability'    => 'edit_posts',
        'redirect'      => true,
        'icon_url'      => 'dashicons-screenoptions',
        'position'      => 22
    ));
    
    acf_add_options_sub_page(array(
        'page_title'    => 'General',
        'menu_title'    => 'General',
        'parent_slug'   => 'theme-general-settings',
    ));
    ...
    }
    
  3. Hi try this $parent['menu_slug']

    if( function_exists('acf_add_options_page') ) {
    
        $parent = acf_add_options_page(array(
            'page_title'    => 'Theme General Settings',
            'menu_title'    => 'General',
            'menu_slug'     => 'theme-general-settings',
            'capability'    => 'edit_posts',
            'redirect'  => false,
        ));
    
        acf_add_options_sub_page(array(
            'page_title'    => 'Header',
            'menu_title'    => 'Header',
            'parent_slug'   => $parent['menu_slug'],
            'capability'    => 'edit_posts',
            'redirect'  => false,
        ));
    
        acf_add_options_sub_page(array(
            'page_title'    => 'Footer',
            'menu_title'    => 'Footer',
            'parent_slug'   => $parent['menu_slug'],
            'capability'    => 'edit_posts',
            'redirect'  => false,
        ));
    
    
    }
    

    https://www.advancedcustomfields.com/resources/acf_add_options_sub_page/

  4. Here is how i got it working:

    if( function_exists('acf_add_options_page') ) {
     acf_add_options_page(array(
      'page_title'  => 'Header Settings',
      'menu_title'  => 'Header',
      'menu_slug'   => 'header-settings'
     ));
    acf_add_options_page(array(
      'page_title'  => 'General Settings',
      'menu_title'  => 'General',
      'menu_slug'   => 'general-settings'
     ));
    acf_add_options_page(array(
      'page_title'  => 'Footer Settings',
      'menu_title'  => 'Footer',
      'menu_slug'   => 'footer-settings'
     ));
    }
    
  5. if( function_exists('acf_add_options_page') ) {
    
        acf_add_options_page(array(
            'page_title'     => 'Theme General Settings',
            'menu_title'    => 'Theme Options',
            'menu_slug'     => 'theme-general-settings',
            'capability'    => 'edit_posts',
            'redirect'        => false,
            'icon_url' => 'dashicons-laptop',
        ));
    }
    

Comments are closed.