Support

Account

Home Forums Backend Issues (wp-admin) Custom options page with (custom post-type) child menu shows top level menu item

Solved

Custom options page with (custom post-type) child menu shows top level menu item

  • I have the following options page.

    
    function noknok_wmp_add_options_page() {
        acf_add_options_page( [
            'page_title'    => __( 'NOKNOK Woocommerce Marketing Platform Settings', NOKNOK_WMP_TEXT_DOMAIN ),
            'menu_title'    => __( 'NOKNOK WMP', NOKNOK_WMP_TEXT_DOMAIN ),
            'update_button' => __( 'Save & Sync', NOKNOK_WMP_TEXT_DOMAIN ),
            'menu_slug'     => 'noknok-wmp-settings',
            'redirect'      => false,
            'capability'    => 'edit_posts',
            'position'      => '3',
            'icon_url'     => NOKNOK_WMP_URL . '/assets/image/icon.png'
        ] );
    }
    
    add_action( 'acf/init', 'noknok_wmp_add_options_page' );
    

    And the following custom post type which I wish to be a sub-menu item of this navigation.

    
            register_post_type( self::ROLE_PROFILE_POST_TYPE, [
                'labels'        => $labels = array_merge(
                    noknok_wmp_post_type_labels( 'Mailerlite Role Sync Profile', 'Mailerlite Role Sync Profiles' ), [
                        'menu_name' => 'Role Profiles',
                        'menu_admin_bar' => 'Role Profiles',
                        'all_items' => 'Role Profiles'
                    ]
                ),
                'description'   => "Adds support for Customer Surveys that can be embedded on pages using shortcodes",
                'public'        => false,
                'hierarchical'  => true,
                'exclude_from_search' => true,
                'publicly_queryable'  => false,
                'show_ui'       => true,
                'show_in_menu'  => 'noknok-wmp-settings',
                "show_in_nav_menus" => false,
                'show_in_admin_bar' => false,
                'capability_type'   => 'page',
                'supports'     => false
            ] );

    This results in the following menu structure
    NOKNOK WMP -> edit.php?post_type=ml_role_profile
    – Role Profiles -> edit.php?post_type=ml_role_profile

    When the post type is not a sub menu item the top level navigation URL works fine although for some strange reason the moment I add a child menu of a post type it no longer functions correctly. Any help appreciated

  • Kind-of fixed, WordPress will automatically assign the topmost sub-menu item as the URL for the main menu item. I fixed this by adding another settings menu as the topmost sub-menu item that redirects to the options page. It’s kinda messy but it works eh…. Open to anymore suggestions.

    
    add_action( 'admin_menu', function() {
        array_unshift( $GLOBALS['submenu']['noknok-wmp-settings'], [
            'Settings',
            'edit_pages',
            'admin.php?page=noknok-wmp-settings'
        ]);
    }, 1000 );
    
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Custom options page with (custom post-type) child menu shows top level menu item’ is closed to new replies.