Q
Q
Quintis2020-09-02 17:31:00
WordPress
Quintis, 2020-09-02 17:31:00

How to display a custom post in the menu?

There are functions that allow you to make a custom post directly from the admin panel:

function my_first_custom_post( ){
    $args = array(
        'labels'=>array(
            'name'=>'Cars',
            'singular_name'=>'Car',
        ),
        'hierarchical'=>true,
        'public'=>true,
        'has_archive'=>true,
        'menu_icon'=> 'dashicons-car',
        'supports'=>array('title','editor','thumbnail','custom-fields'),
        'rewrite'=>array('slug'=>'q-car'),

    );
    register_post_type( 'cars', $args);

};

add_action("init","my_first_custom_post");



function my_first_taxonomy(){
    $args = array(
        'labels'=>array(
            'name'=>'Brands',
            'singular_name'=>'Brand',
        ),
        'public'=>true,
        'hierarchical'=>true,

    );
    register_taxonomy('brands',array('cars'),$args);
}
add_action("init","my_first_taxonomy");

Posts are created, but to add them to the site menu, you need to manually enter the link and text to it. How to make custom posts appear automatically like regular posts or pages?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel Zagainov, 2020-09-02
@Quintis

On the menu editing page, there is a pop-up window at the top - screen settings. Open them and enable your post type

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question