Home Forums Backend Issues (wp-admin) Add submenu to a custom post type menu


Add submenu to a custom post type menu

  • Hello,
    i’d like to add an options page to a custom post type menu in WP admin, and then add custom fields to this option page.

    So far, I managed to create the submenu link; but ACF doesn’t see the sub page.

    Here’s my code :

    ‘page_title’ => ‘Emplacements de diffusion’,
    ‘menu_title’ => ‘Emplacements de diffusion’,
    ‘parent_slug’ => ‘edit.php?post_type=sites’,
    ‘capability’ => ‘edit_sites’,
    ‘menu_slug’ => ‘options_emplacements’,
    ‘function’ => ‘options_emplacements’,

    What am I doing wrong ? How can I use this page within ACF ?

  • if you would like to add option page as a submenu of a custom posttype than use of that custom posttype as parent_slug

    'page_title' 	=> 'Emplacements de diffusion',
    'menu_title' 	=> 'Emplacements de diffusion',
    'menu_slug' 	=> 'options_emplacements',
    'capability' 	=> 'edit_posts', 
    'parent_slug'	=> 'edit.php?post_type=YOURCUSTOMPOSTTYPENAME',
    'position'	=> false,
    'icon_url' 	=> 'dashicons-images-alt2',
    'redirect'	=> false,

    replace YOURCUSTOMPOSTTYPENAME with your customposttype

    hope that is what you wish. else i misunderstood what you would like to do.

    to show acf fields at this site:
    set position rules to => show when options-site is equal to “Emplacements de diffusion”

    to show value at fronpage use <?php the_field('my_acf_field_at_this_optionpage', 'option'); ?>

  • Hi,
    whether I use my code or yours, the location rule tells me “no options page created” : “emplacements de diffusion” is never detected.

    That’s where i’m stuck :/

    Also, are you sure I should be using acf_add_options_page instead of acf_add_options_sub_page ?

  • it depends on which ACF Version you use:

    • acf_add_options_page => ACF 5
    • acf_add_options_sub_page => ACF 4 and Option-Page Add-on

    Edit: had a missing } at my previous posted code, it is now updated.

    where did you try to add the option page?
    have you try to add it as first function inside your functions.php ?

  • I’m using ACF 5, and I added the missing }

    I’m adding the function in a plugin file : I want to be able to add an options sub page to a CPT menu, and so far, I’m able to create and register the page, but ACF won’t detect it in the location rules.

  • fine 🙂 then you can should use my code.

    hmm, dont know if it is possible to add it with plugin, because i dont know if this is true, when used with plugin:
    This function must be used before the action admin_menu (priority 99) as this is when the options pages are added to WordPress.

    just for testing, could you try to add it with functions.php and look if it works then

    maybe it would also work if you wrap that function inside your plugin with that code: to init it before admin_menu is created

    add_action('init', 'add_my_options_pages');
    function add_my_options_pages() {
        // put code from above in this function
Viewing 6 posts - 1 through 6 (of 6 total)

The topic ‘Add submenu to a custom post type menu’ is closed to new replies.