How to Add a Sub Menu Page to a Custom Post Type?

I am trying to create a sub-menu under a Custom Post Type I have named Portfolios.

When I change add_submenu_page() to add_options_page(), it correctly shows a new link under the Settings menu, but it doesn’t show under the Portfolios menu.

What am I doing wrong?

Below is my code snippet;

add_action( 'admin_menu', 'mt_add_pages' );

function mt_add_pages() {
    add_submenu_page(
        __( 'portfolios', 'menu-test' ),
        __( 'Test Settings', 'menu-test' ),
        'manage_options',
        'testsettings',
        'mt_settings_page'
    );

    function mt_settings_page() {
        echo "<h2>" . __( 'Test Settings', 'menu-test' ) . "</h2>";
    }
}

4

add_options_page() automatically adds it underneath settings, however add_submenu_page() gives you control as to where you want it to show up.

Try something like this:

add_submenu_page(
    'edit.php?post_type=portfolios',
    __( 'Test Settings', 'menu-test' ),
    __( 'Test Settings', 'menu-test' ),
    'manage_options',
    'testsettings',
    'mt_settings_page'
);

Leave a Comment