You want to create a submenu below the custom post type menu. This is very easy to do with just a short piece of code.
However, before we begin. Make sure you know how to create custom post types in WordPress. If you are still unsure, read this article .

Register custom post type
First, to be able to create the submenu below, you must register a custom post type.
The code below will help you to register a new custom post type. Add this code to the functions.php file of your theme or child theme.
// Register Custom Post Type
function event_post_type() {
$labels = array(
'name' => _x( 'Sự kiện', 'Post Type General Name', 'hocwordpress' ),
'singular_name' => _x( 'Sự kiện', 'Post Type Singular Name', 'hocwordpress' ),
'menu_name' => __( 'Sự kiện', 'hocwordpress' ),
'name_admin_bar' => __( 'Sự kiện', 'hocwordpress' ),
'archives' => __( 'Item Archives', 'hocwordpress' ),
'attributes' => __( 'Item Attributes', 'hocwordpress' ),
'parent_item_colon' => __( 'Parent Item:', 'hocwordpress' ),
'all_items' => __( 'Tất cả sự kiện', 'hocwordpress' ),
'add_new_item' => __( 'Add New Item', 'hocwordpress' ),
'add_new' => __( 'Thêm sự kiện', 'hocwordpress' ),
'new_item' => __( 'New Item', 'hocwordpress' ),
'edit_item' => __( 'Edit Item', 'hocwordpress' ),
'update_item' => __( 'Update Item', 'hocwordpress' ),
'view_item' => __( 'View Item', 'hocwordpress' ),
'view_items' => __( 'View Items', 'hocwordpress' ),
'search_items' => __( 'Search Item', 'hocwordpress' ),
'not_found' => __( 'Not found', 'hocwordpress' ),
'not_found_in_trash' => __( 'Not found in Trash', 'hocwordpress' ),
'featured_image' => __( 'Featured Image', 'hocwordpress' ),
'set_featured_image' => __( 'Set featured image', 'hocwordpress' ),
'remove_featured_image' => __( 'Remove featured image', 'hocwordpress' ),
'use_featured_image' => __( 'Use as featured image', 'hocwordpress' ),
'insert_into_item' => __( 'Insert into item', 'hocwordpress' ),
'uploaded_to_this_item' => __( 'Uploaded to this item', 'hocwordpress' ),
'items_list' => __( 'Items list', 'hocwordpress' ),
'items_list_navigation' => __( 'Items list navigation', 'hocwordpress' ),
'filter_items_list' => __( 'Filter items list', 'hocwordpress' ),
);
$args = array(
'label' => __( 'Sự kiện', 'hocwordpress' ),
'description' => __( 'Sự kiện', 'hocwordpress' ),
'labels' => $labels,
'supports' => array( 'title', 'editor', 'thumbnail' ),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 5,
'menu_icon' => 'dashicons-beer',
'show_in_admin_bar' => true,
'show_in_nav_menus' => true,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'page',
);
register_post_type( 'event', $args );
}
add_action( 'init', 'event_post_type', 0 );
<div>
<span>1</span><span>2</span><span>3</span><span>4</span><span>5</span><span>6</span><span>7</span><span>8</span><span>9</span><span>10</span><span>11</span><span>12</span><span>13</span><span>14</span><span>15</span><span>16</span><span>17</span><span>18</span><span>19</span><span>20</span><span>21</span><span>22</span><span>23</span><span>24</span><span>25</span><span>26</span><span>27</span><span>28</span><span>29</span><span>30</span><span>31</span><span>32</span><span>33</span><span>34</span><span>35</span><span>36</span><span>37</span><span>38</span><span>39</span><span>40</span><span>41</span><span>42</span><span>43</span><span>44</span><span>45</span><span>46</span><span>47</span><span>48</span><span>49</span><span>50</span><span>51</span><span>52</span><span>53</span><span>54</span><span>55</span>
</div>
The result you will get is a new menu called “Events”.

Add submenu for custom post type menu
To create a submenu under the “Events” menu, you must use the WordPress add_submenu_page() function . Add the following code to the functions.php file below the post type registration code above.
// Hook
add_action('admin_menu', 'hk_demo_submenu_event');
// admin_menu callback function
function hk_demo_submenu_event(){
add_submenu_page(
'edit.php?post_type=event', #1 Slug menu cha
'Demo Tiêu đề', #2 Tiêu đề trang
'Demo Menu', #3 Tiêu đề menu
'manage_options',
'demo_menu', #4 Slug menu con
'hk_render_page' #5 callback function
);
}
// add_submenu_page callback function
function hk_render_page() {
echo '<h2>HocWordPress.vn</h2>';
}
<div>
<span>1</span><span>2</span><span>3</span><span>4</span><span>5</span><span>6</span><span>7</span><span>8</span><span>9</span><span>10</span><span>11</span><span>12</span><span>13</span><span>14</span><span>15</span><span>16</span><span>17</span><span>18</span><span>19</span><span>20</span><span>21</span>
</div>
After adding the above code to the function file, the result you will get is as shown below. The figure below also includes annotations for the elements in the add_submenu_page() function.

Epilogue
I hope you can apply this solution in your WordPress theme or plugin development. Especially when you need to create several settings pages for custom post types.
If you found this article useful, please comment and share this article. In addition, you can follow the WordPress Tips section and follow Facebook for more new knowledge.

