How to add custom post type to nav_menu in Wordpress?

31,737

The function register_post_type() takes an argument show_in_nav_menus. If you set this to TRUE you get a selector for your custom post type in the menu manager.

Sample code

    register_post_type(
        'post_type_name'
    ,   array (
            'can_export'          => TRUE
        ,   'exclude_from_search' => FALSE
        ,   'has_archive'         => TRUE
        ,   'hierarchical'        => TRUE
        ,   'label'               => 'CPT Test'
        ,   'menu_position'       => 5
        ,   'public'              => TRUE
        ,   'publicly_queryable'  => TRUE
        ,   'query_var'           => 'cpttest'
        ,   'rewrite'             => array ( 'slug' => 'cpt-test' )
        ,   'show_ui'             => TRUE
        ,   'show_in_menu'        => TRUE
        ,   'show_in_nav_menus'   => TRUE
        ,   'supports'            => array ( 'editor', 'title' )
        )
    );

Screen shot

Screen shot with the custom post type named CPT Test.

Share:
31,737

Related videos on Youtube

Steffi
Author by

Steffi

Updated on July 09, 2022

Comments

  • Steffi
    Steffi almost 2 years

    I have a question.

    I use the new custom menus of Wordpress 3.0. And I'm wondering how can I add custom post types to the menu. For now, I can just add Pages and Categories.

    Thanks

  • Musaddiq Khan
    Musaddiq Khan almost 10 years
    can you please explain what is the value of the variable $this->post_type as I have used the same code and my custom post name is not appearing in the screen option.
  • fuxia
    fuxia almost 10 years
    @MusaddiqKhan It is the name of the post type. I have edited my answer.
  • Musaddiq Khan
    Musaddiq Khan almost 10 years
    Thanks for your feedback, I will check my code for other errors.
  • fuxia
    fuxia almost 10 years
    @MusaddiqKhan Make sure the box is not disabled in the Screen Options. Happened to me one time. :)