How to Add a Setting Page To wordpress Custom Post Type
In this Article I am going to Explain how to add a Setting Page To Custom Post Type, Recently I needed to add a settings page to two custom post types I am developing a plugin for a client . Adding an admin page to one of the default menus in the WordPress control panel is easy. The WordPress Codex has a nice article explaining how to hook sub-menu pages to “posts” “media” “categories” and so on.
It’s very useful for plugins and theme authors. One thing the article doesn’t do is explain how to add a sub-menu to a custom post type. Turns out, it’s easy to do. Here’s the code we will use and a brief explanation of it.
add_action(‘admin_menu’ , ‘tradmin_page_settings’); function tradmin_page_settings() { add_submenu_page(‘edit.php?post_type=custom’, ‘Custom Post Type Admin’, ‘Custom Settings’, ‘edit_posts’, basename(__FILE__), ‘custom_fuction’); }
first of all we add an action for our new admin menu, Once we’ve done that, you need to create a function for your page(s). Here’s what the function does. First we are saying the place we’d like the menu to go is with the post type we’ve defined called “custom.” That’s what the edit.php?post_type=custom part is dong. Just replace “custom” with the post type that you’ve already defined and the menu will be added there
add_action(‘admin_menu’ , ‘tradmin_page_settings’);
Our next two options deal with titles and menu names. The ‘Custom Post Type Admin’ is the page title that will appear at the top of your browser page while using the page. The ‘Custom Settings’ is the name that will appear in your menu under your custom post type.
The ‘edit_posts’ set the minimum capabilities a user has to have in order to access this page. If the current user can edit posts then they can access our admin page
The ‘basename(__FILE__)’ serves as the slug that will go in your URL for the admin page you create. Lastly the ‘custom_function’ is optional and will call any functions you need on your new admin page
Responses (2)
I am working on a project with wordpress custom post type, i need a custom admin settings page, can you do this and please let me know a cost to do the work?
Hi Paul,
Surely, we can help you, just send a mail to this E-mail Id (Support@techieresource.com) so that we can discuss further.