Add a submenu to WordPress’s custom post type menu.

If you want to add a submenu item to the custom post type menu, please use a simple code snippet to complete it easily. Ideally, the custom post type menu includes new posts, categories and all post add menus by default, but other submenu items can be added to the word press settings management page. Before you learn how to add submenus to the custom post type menu, it is important to understand how to register custom post types in word press without using plug-ins. To display the submenu under the user-defined article type menu, the slug of the user-defined article type needs to be one of the parameters of the add_subnu_page() function. Therefore, we will begin to quickly explore how to register custom post types in WordPress topics.
Registers a custom post type, but describes all the details of how to add a custom post type to WordPress in this post. WordPress quickly shares the code needed to add custom post types. The code for registering custom post type is as follows:\/**
*Custom post type – register_post_type ()
*@Description njengah tutorial custom post type example
*@Link- https:\/\/gist.github.com\/Njengah\/839466b773085ac2430772e081357cee
*
*\/
Add_action (\
Function njengah_tutorial_cpt (){
$labels = array(
\
\
\
\
\
\
\
\
\
\
\
\
\
\
);
$args = array(
\
‘labels’ => $labels,
\
>By the way,
\
\
\
\
\
\
\
\
\
“capability_type”=>“page”,
\
\
\
‘supports’ => array( ‘title’, ‘editor’, ‘author’, ‘thumbnail’, ‘revisions’, ‘page-attributes’, ‘custom-fields’ )
);
Register_post_type (\
}Functions in subtopics. It must be added to the PHP file, and the custom post type must be displayed on the dashboard, as shown below:
This code can also be added to the custom word press plug-in to register the custom post type. You must also replace the \
Create an action hook, and each callback function registers a submenu. In this case, you must create two functions. The first parameter of add_subminu_page() is the specific editing post type slug sample PHP? Post_type = replace with \
The add_subminu_page() function takes 7 parameters by default, and the general code is as follows: add_submenu_page(
String $parent_slug,
String $page_title,
String $menu_title,
String $function,
String $menu_slug,
Callable $function = \
int$Position=null
)The function parameters of other submenu pages can be described as follows:
Male parameter male explanation male $par
Ent_slug malemale this is the slug name of the upper menu example. In this case, edit. php? post_type=“tutorials”。 Male $page _title _title _title _title _title _title _example _menu _title _example _tutorials _title _title _example _tutorials The slug of the page for which you want to generate the \
To register the user-defined post type in the parent slug parameter, add the following function to register the code of the tutorial user-defined post type. You must add the following code to your PHP file\/**
*Add sub page to custom post type custom post menu
*@Description njengah tutorial custom post type submenu example
*@Link- https:\/\/gist.github.com\/Njengah\/0764f2c88742c19b67a212c914c9f25f
*
*\/
\/\/Hook up
add_action(‘admin_menu’, ‘add_tutorial_cpt_submenu_example’);
\/\/Admin_menu callback function
Function add_tutorial_cpt_subnu_example(){
add_submenu_page(
‘edit. php? Post_type = \
\
\
‘manage_options’, \/\/$capability
‘tutorial_subpage_example’,\/\/$menu_slug
\
);
}
\/\/Add_subnu_page callback function
Function tutorial_subpage_example_render_page(){
Echo \
} functions. If you add the code to the PHP or plug-in default file, the following tutorials settings are added and all the parameters discussed above are displayed as described in the following image.
Male conclusion the code is the function of the subject. You can easily add submenus to PHP and adjust them to successfully add submenus to the custom article type menu. In this tutorial, the parent slug of the add_subnu_page function adds a submenu page to the custom article type menu, so the custom article type slug will be added. Especially in word press theme development that requires partial setup pages of specific custom post types, we hope this solution will be available. This is indeed an ideal solution.

Author:

Leave a Reply

Your email address will not be published. Required fields are marked *