Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save espiat/25873a44c3d45bdb2a676f4f24608404 to your computer and use it in GitHub Desktop.
Save espiat/25873a44c3d45bdb2a676f4f24608404 to your computer and use it in GitHub Desktop.
Simple function to add submenu page to a custom post type menu in WordPress admin
<?php
// Hook
add_action('admin_menu', 'add_tutorial_cpt_submenu_example');
//Callback function
function add_tutorial_cpt_submenu_example(){
add_submenu_page(
'edit.php?post_type=tutorial', //$parent_slug
'Tutorial Subpage Example', //$page_title
'Tutorial Settings', //$menu_title
'manage_options', //$capability
'tutorial_subpage_example',//$menu_slug
'tutorial_subpage_example_render_page'//$function
);
}
//callback function
function tutorial_subpage_example_render_page() {
echo '<h2> Tutorial Subpage Example </h2>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment