ACF options add submenu with a callback function










0















i want to add a custom submenu to option page so that i can render page with callback function i add. if i create acf_add_options_sub_page i must use the acf field to generate the options page.



if( function_exists('acf_add_options_page') ) 

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' => 'Theme Header Settings',
'menu_title' => 'Header',
'parent_slug' => 'theme-general-settings',
));

acf_add_options_sub_page(array(
'page_title' => 'Theme Footer Settings',
'menu_title' => 'Footer',
'parent_slug' => 'theme-general-settings',
));





What i tried



add_action( 'admin_menu', 'main_home' );

/**
* Adds a submenu page under a custom post type parent.
*/
function main_home()
add_submenu_page(
'theme-general-settings',
__( 'Books Shortcode Reference', 'textdomain' ),
__( 'Shortcode Reference', 'textdomain' ),
'manage_options',
'books-shortcode-ref',
'books_ref_page_callback'
);


/**
* Display callback for the submenu page.
*/
function books_ref_page_callback()
?>
<div class="wrap">
<h1><?php _e( 'Books Shortcode Reference', 'textdomain' ); ?></h1>
<p><?php _e( 'Helpful stuff here', 'textdomain' ); ?></p>
</div>
<?php



Result
It does not work : url becomes like : website.com/wp-admin/books-shortcode-ref



if i change books-shortcode-ref to theme-general-settings it works but the it becomes same as what acf plugin used to go ..i have to add options using acf fields



Please help










share|improve this question


























    0















    i want to add a custom submenu to option page so that i can render page with callback function i add. if i create acf_add_options_sub_page i must use the acf field to generate the options page.



    if( function_exists('acf_add_options_page') ) 

    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' => 'Theme Header Settings',
    'menu_title' => 'Header',
    'parent_slug' => 'theme-general-settings',
    ));

    acf_add_options_sub_page(array(
    'page_title' => 'Theme Footer Settings',
    'menu_title' => 'Footer',
    'parent_slug' => 'theme-general-settings',
    ));





    What i tried



    add_action( 'admin_menu', 'main_home' );

    /**
    * Adds a submenu page under a custom post type parent.
    */
    function main_home()
    add_submenu_page(
    'theme-general-settings',
    __( 'Books Shortcode Reference', 'textdomain' ),
    __( 'Shortcode Reference', 'textdomain' ),
    'manage_options',
    'books-shortcode-ref',
    'books_ref_page_callback'
    );


    /**
    * Display callback for the submenu page.
    */
    function books_ref_page_callback()
    ?>
    <div class="wrap">
    <h1><?php _e( 'Books Shortcode Reference', 'textdomain' ); ?></h1>
    <p><?php _e( 'Helpful stuff here', 'textdomain' ); ?></p>
    </div>
    <?php



    Result
    It does not work : url becomes like : website.com/wp-admin/books-shortcode-ref



    if i change books-shortcode-ref to theme-general-settings it works but the it becomes same as what acf plugin used to go ..i have to add options using acf fields



    Please help










    share|improve this question
























      0












      0








      0








      i want to add a custom submenu to option page so that i can render page with callback function i add. if i create acf_add_options_sub_page i must use the acf field to generate the options page.



      if( function_exists('acf_add_options_page') ) 

      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' => 'Theme Header Settings',
      'menu_title' => 'Header',
      'parent_slug' => 'theme-general-settings',
      ));

      acf_add_options_sub_page(array(
      'page_title' => 'Theme Footer Settings',
      'menu_title' => 'Footer',
      'parent_slug' => 'theme-general-settings',
      ));





      What i tried



      add_action( 'admin_menu', 'main_home' );

      /**
      * Adds a submenu page under a custom post type parent.
      */
      function main_home()
      add_submenu_page(
      'theme-general-settings',
      __( 'Books Shortcode Reference', 'textdomain' ),
      __( 'Shortcode Reference', 'textdomain' ),
      'manage_options',
      'books-shortcode-ref',
      'books_ref_page_callback'
      );


      /**
      * Display callback for the submenu page.
      */
      function books_ref_page_callback()
      ?>
      <div class="wrap">
      <h1><?php _e( 'Books Shortcode Reference', 'textdomain' ); ?></h1>
      <p><?php _e( 'Helpful stuff here', 'textdomain' ); ?></p>
      </div>
      <?php



      Result
      It does not work : url becomes like : website.com/wp-admin/books-shortcode-ref



      if i change books-shortcode-ref to theme-general-settings it works but the it becomes same as what acf plugin used to go ..i have to add options using acf fields



      Please help










      share|improve this question














      i want to add a custom submenu to option page so that i can render page with callback function i add. if i create acf_add_options_sub_page i must use the acf field to generate the options page.



      if( function_exists('acf_add_options_page') ) 

      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' => 'Theme Header Settings',
      'menu_title' => 'Header',
      'parent_slug' => 'theme-general-settings',
      ));

      acf_add_options_sub_page(array(
      'page_title' => 'Theme Footer Settings',
      'menu_title' => 'Footer',
      'parent_slug' => 'theme-general-settings',
      ));





      What i tried



      add_action( 'admin_menu', 'main_home' );

      /**
      * Adds a submenu page under a custom post type parent.
      */
      function main_home()
      add_submenu_page(
      'theme-general-settings',
      __( 'Books Shortcode Reference', 'textdomain' ),
      __( 'Shortcode Reference', 'textdomain' ),
      'manage_options',
      'books-shortcode-ref',
      'books_ref_page_callback'
      );


      /**
      * Display callback for the submenu page.
      */
      function books_ref_page_callback()
      ?>
      <div class="wrap">
      <h1><?php _e( 'Books Shortcode Reference', 'textdomain' ); ?></h1>
      <p><?php _e( 'Helpful stuff here', 'textdomain' ); ?></p>
      </div>
      <?php



      Result
      It does not work : url becomes like : website.com/wp-admin/books-shortcode-ref



      if i change books-shortcode-ref to theme-general-settings it works but the it becomes same as what acf plugin used to go ..i have to add options using acf fields



      Please help







      php wordpress advanced-custom-fields options






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 14 '18 at 23:23









      Latheesh V M VillaLatheesh V M Villa

      14619




      14619






















          1 Answer
          1






          active

          oldest

          votes


















          1














          Here the code I've just used to add custom sub option page to ACF option page applyed to your exemple. You have to declare your option page twice with the same identifier (in ACF and with the normal way).So, It's a little tricky, but it works :



          function add_acf_option_page() 
          if( function_exists('acf_add_options_page') )
          acf_add_options_page(array(
          'page_title' => 'Theme General Settings',
          'menu_title' => 'Theme Settings',
          'menu_slug' => 'theme-general-settings',
          'capability' => 'manage_options',
          'redirect' => false
          ));
          acf_add_options_sub_page( array(
          'page_title' => __( 'Books Shortcode Reference', 'textdomain' ),
          'menu_title' => __( 'Shortcode Reference', 'textdomain' ),
          'parent_slug' => 'theme-general-settings',
          'capability' => 'manage_options',
          'menu_slug' => 'books-ref-page',
          ) );


          add_action('acf/init', 'add_acf_option_page' );

          function add_custom_option_page()
          add_submenu_page(
          null,
          __( 'Books Shortcode Reference', 'textdomain' ),
          __( 'Shortcode Reference', 'textdomain' ),
          'manage_options',
          'books-ref-page',
          'books_ref_page_callback'

          add_action('admin_menu', 'add_custom_option_page');

          function books_ref_page_callback()
          ?>
          <div class="wrap">
          <h1><?php _e( 'Books Shortcode Reference', 'textdomain' ); ?></h1>
          <p><?php _e( 'Helpful stuff here', 'textdomain' ); ?></p>
          </div>
          <?php



          I hope it's help !






          share|improve this answer






















            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53310266%2facf-options-add-submenu-with-a-callback-function%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            Here the code I've just used to add custom sub option page to ACF option page applyed to your exemple. You have to declare your option page twice with the same identifier (in ACF and with the normal way).So, It's a little tricky, but it works :



            function add_acf_option_page() 
            if( function_exists('acf_add_options_page') )
            acf_add_options_page(array(
            'page_title' => 'Theme General Settings',
            'menu_title' => 'Theme Settings',
            'menu_slug' => 'theme-general-settings',
            'capability' => 'manage_options',
            'redirect' => false
            ));
            acf_add_options_sub_page( array(
            'page_title' => __( 'Books Shortcode Reference', 'textdomain' ),
            'menu_title' => __( 'Shortcode Reference', 'textdomain' ),
            'parent_slug' => 'theme-general-settings',
            'capability' => 'manage_options',
            'menu_slug' => 'books-ref-page',
            ) );


            add_action('acf/init', 'add_acf_option_page' );

            function add_custom_option_page()
            add_submenu_page(
            null,
            __( 'Books Shortcode Reference', 'textdomain' ),
            __( 'Shortcode Reference', 'textdomain' ),
            'manage_options',
            'books-ref-page',
            'books_ref_page_callback'

            add_action('admin_menu', 'add_custom_option_page');

            function books_ref_page_callback()
            ?>
            <div class="wrap">
            <h1><?php _e( 'Books Shortcode Reference', 'textdomain' ); ?></h1>
            <p><?php _e( 'Helpful stuff here', 'textdomain' ); ?></p>
            </div>
            <?php



            I hope it's help !






            share|improve this answer



























              1














              Here the code I've just used to add custom sub option page to ACF option page applyed to your exemple. You have to declare your option page twice with the same identifier (in ACF and with the normal way).So, It's a little tricky, but it works :



              function add_acf_option_page() 
              if( function_exists('acf_add_options_page') )
              acf_add_options_page(array(
              'page_title' => 'Theme General Settings',
              'menu_title' => 'Theme Settings',
              'menu_slug' => 'theme-general-settings',
              'capability' => 'manage_options',
              'redirect' => false
              ));
              acf_add_options_sub_page( array(
              'page_title' => __( 'Books Shortcode Reference', 'textdomain' ),
              'menu_title' => __( 'Shortcode Reference', 'textdomain' ),
              'parent_slug' => 'theme-general-settings',
              'capability' => 'manage_options',
              'menu_slug' => 'books-ref-page',
              ) );


              add_action('acf/init', 'add_acf_option_page' );

              function add_custom_option_page()
              add_submenu_page(
              null,
              __( 'Books Shortcode Reference', 'textdomain' ),
              __( 'Shortcode Reference', 'textdomain' ),
              'manage_options',
              'books-ref-page',
              'books_ref_page_callback'

              add_action('admin_menu', 'add_custom_option_page');

              function books_ref_page_callback()
              ?>
              <div class="wrap">
              <h1><?php _e( 'Books Shortcode Reference', 'textdomain' ); ?></h1>
              <p><?php _e( 'Helpful stuff here', 'textdomain' ); ?></p>
              </div>
              <?php



              I hope it's help !






              share|improve this answer

























                1












                1








                1







                Here the code I've just used to add custom sub option page to ACF option page applyed to your exemple. You have to declare your option page twice with the same identifier (in ACF and with the normal way).So, It's a little tricky, but it works :



                function add_acf_option_page() 
                if( function_exists('acf_add_options_page') )
                acf_add_options_page(array(
                'page_title' => 'Theme General Settings',
                'menu_title' => 'Theme Settings',
                'menu_slug' => 'theme-general-settings',
                'capability' => 'manage_options',
                'redirect' => false
                ));
                acf_add_options_sub_page( array(
                'page_title' => __( 'Books Shortcode Reference', 'textdomain' ),
                'menu_title' => __( 'Shortcode Reference', 'textdomain' ),
                'parent_slug' => 'theme-general-settings',
                'capability' => 'manage_options',
                'menu_slug' => 'books-ref-page',
                ) );


                add_action('acf/init', 'add_acf_option_page' );

                function add_custom_option_page()
                add_submenu_page(
                null,
                __( 'Books Shortcode Reference', 'textdomain' ),
                __( 'Shortcode Reference', 'textdomain' ),
                'manage_options',
                'books-ref-page',
                'books_ref_page_callback'

                add_action('admin_menu', 'add_custom_option_page');

                function books_ref_page_callback()
                ?>
                <div class="wrap">
                <h1><?php _e( 'Books Shortcode Reference', 'textdomain' ); ?></h1>
                <p><?php _e( 'Helpful stuff here', 'textdomain' ); ?></p>
                </div>
                <?php



                I hope it's help !






                share|improve this answer













                Here the code I've just used to add custom sub option page to ACF option page applyed to your exemple. You have to declare your option page twice with the same identifier (in ACF and with the normal way).So, It's a little tricky, but it works :



                function add_acf_option_page() 
                if( function_exists('acf_add_options_page') )
                acf_add_options_page(array(
                'page_title' => 'Theme General Settings',
                'menu_title' => 'Theme Settings',
                'menu_slug' => 'theme-general-settings',
                'capability' => 'manage_options',
                'redirect' => false
                ));
                acf_add_options_sub_page( array(
                'page_title' => __( 'Books Shortcode Reference', 'textdomain' ),
                'menu_title' => __( 'Shortcode Reference', 'textdomain' ),
                'parent_slug' => 'theme-general-settings',
                'capability' => 'manage_options',
                'menu_slug' => 'books-ref-page',
                ) );


                add_action('acf/init', 'add_acf_option_page' );

                function add_custom_option_page()
                add_submenu_page(
                null,
                __( 'Books Shortcode Reference', 'textdomain' ),
                __( 'Shortcode Reference', 'textdomain' ),
                'manage_options',
                'books-ref-page',
                'books_ref_page_callback'

                add_action('admin_menu', 'add_custom_option_page');

                function books_ref_page_callback()
                ?>
                <div class="wrap">
                <h1><?php _e( 'Books Shortcode Reference', 'textdomain' ); ?></h1>
                <p><?php _e( 'Helpful stuff here', 'textdomain' ); ?></p>
                </div>
                <?php



                I hope it's help !







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Feb 4 at 16:04









                LucLuc

                10612




                10612





























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53310266%2facf-options-add-submenu-with-a-callback-function%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    這個網誌中的熱門文章

                    Barbados

                    How to read a connectionString WITH PROVIDER in .NET Core?

                    Node.js Script on GitHub Pages or Amazon S3