Add A Custom Post Type Admin Menu

Add A Setting Page To Custom Post Type

Recently I needed to add a settings page to two custom post types I was using in a new theme. 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.

<?php

add_action('admin_menu' , 'brdesign_enable_pages'); 

function brdesign_enable_pages() {
    add_submenu_page('edit.php?post_type=custom', 'Custom Post Type Admin', 'Custom Settings', 'edit_posts', basename(__FILE__), 'custom_function');
}

?>

First we add an action for our new admin menu. Once we’ve done that, we create a function for our 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. If you need help registering a custom post type, here’s a great article on the subject by Justin Tadlock.

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 Codex has a list of roles and capabilities you can see to help determine what to place here.

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.

That’s all there is to it. Now you can easily add a settings page to enhance your custom post types.

8 Comments On “Add A Setting Page To Custom Post Type”

  1. So I’m looking for a way to kinda do the reverse of this and place custom post types in my plugin.

    thought that this would simply do the trick:

    ‘show_in_menu’ => ‘admin.php?page=plugin_admin’

    page=plugin_admin is one of my submenu pages, so I don’t think I’m doing something right.

    You have any experience doing this?

    • That’s one I haven’t tried myself. I took a look at a couple of plugins that use custom post types. Both of those use the post type as the main menu element with supporting settings and taxonomies under it instead of the other way around. The Codex indicates that what you’d like to do is possible:

      “Note: When using ‘some string’ to show as a submenu of a menu page created by a plugin, this item will become the first submenu item, and replace the location of the top level link. If this isn’t desired, the plugin that creates the menu page needs to set the add_action priority for admin_menu to 9 or lower. http://codex.wordpress.org/Function_Reference/register_post_type

      It wouldn’t discuss menu order unless it was possible to add a post type to a plugin’s menu section.

    • I just ran into this myself. Were you ever able to find a resolution? It looks like theres an issue when adding a CPT to anything under admin.php.

      • I honestly haven’t looked at it lately. I’ve started developing a new plugin anyway could use that. If I figure out a solution, I’ll post it.

        If anyone else has a solution, please feel free to post it.

  2. Thank you for this post. Can you help me, please? I am having problem: I want create a menu in WordPress admin contained have many child custom post type to easy to manage. Example:

    Menu Facilities include post types: – Meetings; – Weddings; – SPA

    Thanks for help very much.

  3. How can I make spots to add adsense codes, choose in the options page an specific category to show in the home? You can help me? Thanks

    • Edd,

      It’s a bit off topic, but you can do that. The best way to specify where your adsense would display is to use a sidebar manager plugin like Woosidebars that lets you create new sidebars that appear in the locations you choose (by page, by post, by category and so on).

      Once you’ve made a sidebar that you’d like to use, then just add your adsence code to a text widget and you’ll display that ad in the location you just created.

      Hope that helps,
      Bill

Leave a Reply