How can I get my Custom Post Types to appear in nav-menus.php ‘Menu’?

I am having a bit of a problem with my custom post types. I can create them fine in my theme, but I cannot get them to show up in the ‘Menu’ screen … at least not by default.

I have tried adding menu and UI flags to my code (see below), but no dice.

Read More

Interestingly enough, when I enable the Custom Post Types UI plugin, the custom post types appear fine (sometimes) in the ‘Menu’ screen. This seems to suggest to me that there is a step that I am missing somewhere, and that somehow, the Custom Post Types UI plugin sets that flag, and allows my custom post type, and taxonomies to appear in the nav-menus.php ‘Menu’ screen.

edit:: The bit above has been answered. Thank you Milo. I should have been turning them on in the ‘Screen Option’ tab.

On a related note, is there a way of getting the custom post type available as a menu item without using a taxonomy? I’ll try and explain. In this instance, I created a portfolio post type.

a. When it does appear in the nav-menus.php, I can select individual pages to add to the menu. This is not ideal.

b. Alternatively, I can assign the portfolio pages to a category (let’s call it Widgets), and all pages assigned to widgets appear on the archive page. This raises another question, can I force the assigning of every new portfolio page to at least one default category, like the ‘Posts’ behave in WP? This solution works most of the time, till someone forgets to assign a category to a new portfolio page …

c. The third option, is to use the rewrite slug, and just create a custom menu item, point to (in this case) ‘/portfolio/’. This works fine with my permalinks. However, WordPress does then not add ‘.current-post-item’, or ‘.current-menu-parent’ or ‘.current-post-parent’ classes to this menu item when viewing a portfolio page, meaning that I cannot use CSS to highlight the ‘Portfolio’ menu entry when viewing portfolio pages, like I can with all the other pages/subpages and posts on the site. While this is not an overly big deal, it does mean a less than consistent UI experience for site visitors.

Here is my code for registering the custom post types. As you can see, I have been adding a ton of the ‘show_in_…’ flags, but to no avail. I have tried removing the flags, adding them one at a time and testing (with a clean database each time), but to no avail. As I pointed out above, that the Custom Post Types UI plugin seems to enable this behaviour (most of the time), seems to suggest that I am missing a step outside this registration code.

Thank you in advance.

add_action( 'init', 'toshihiro_register_portfolio_content_type');
function toshihiro_register_portfolio_content_type(){
    register_post_type('tosh_portfolio',
    array(
         'labels' => array (
             'name' => 'Portfolio Pages',
             'singular_name' => 'Portfolio Page',
             'menu_name' => 'Portfolios',
             'add_new' => 'Create Portfolio Page',
             'add_new_item' => 'Create New Portfolio Page',
             'edit' => 'Edit Portfolio Page',
             'edit_item' => 'Edit Portfolio Page',
             'new_item' => 'New Portfolio Page',
             'view' => 'View Portfolio Page',
             'view_item' => 'View Portfolio Page',
             'search_items' => 'Search Portfolio Pages',
             'not_found' => 'No Portfolio Pages Found',
             'not_found_in_trash' => 'No Portfolio Pages found in Trash',
         ),
        'description' => 'Portfolio or product or project pages',
        'supports' => array('title', 'editor', 'excerpt', 'revisions', 'thumbnail'),
        'public' => true,
        'show_ui' => true,
        'show_in_menu' => true,
        'show_in_nav_menus' => true,
        'query_var' => true,
        'has_archive' => true,
        'hierarchical' => false,
        'can_export' => true,
        'menu_icon' => trailingslashit(TOSH_IMAGES_URI) . 'toshihiro_icon.png',
        'menu_position' => 33,
        'rewrite' => array('slug' => 'portfolio'),
    )
);
register_taxonomy('tosh_cat_port',array (0 => 'tosh_portfolio',),array( 'hierarchical' => true,
                                                            'label' => 'Portfolio Categories',
                                                            'singular_label' => 'Portfolio Category',
                                                            'show_ui' => true,
                                                            'query_var' => true,
                                                            'show_in_nav_menus' => true,
                                                            'rewrite' => array('slug' => 'portfolio_cat'),
                                                             ) );
register_taxonomy('tosh_tag_port',array (0 => 'tosh_portfolio',),array( 'hierarchical' => false,
                                                            'label' => 'Portfolio Tags',
                                                            'singular_label' => 'Portfolio Tag',
                                                            'show_ui' => true,
                                                            'show_in_nav_menus' => true,
                                                            'query_var' => true,
                                                            'rewrite' => array('slug' => 'portfolio_tags'),
                                                             ) );
}

Related posts

Leave a Reply

2 comments

  1. You can force the custom post type to stay on by editing the current user option ‘metaboxhidden_nav-menus’:

    function display_post_type_nav_box(){
    
        $hidden_nav_boxes = get_user_option( 'metaboxhidden_nav-menus' );
    
        $post_type = 'foobar'; //Can also be a taxonomy slug
        $post_type_nav_box = 'add-'.$post_type;
    
        if(in_array($post_type_nav_box, $hidden_nav_boxes)):
            foreach ($hidden_nav_boxes as $i => $nav_box):
                if($nav_box == $post_type_nav_box)
                    unset($hidden_nav_boxes[$i]);
            endforeach;
            update_user_option(get_current_user_id(), 'metaboxhidden_nav-menus', $hidden_nav_boxes);
        endif;
    }
    add_action('admin_init', 'display_post_type_nav_box');