custom post type remove add new option

Custom post type shorthand is CPT.

Custom post type is allow users to customize in own way, CPT customize is very flexible, you can add own Custom post type name, slug and capabilities etc.

here, I can show how to create Custom post type and how to hide Add new button from there.

First of all you don’t have idea about how to create Custom post type WordPress follow this perfect article : How to make Custom Post type in wordpress?

Add new option show like below images

add new in sub menu custom post type

Also remove from custom post type page like below image

add new on custom post type page

Go to your active child theme or parent theme and open functions.php file and paste below code for hide Add new option  from Custom post type.

I have show you two methods to hide add new option from custom post type –

First method:-

First method is default is come from Custom pos type default functions,

Find you have added the custom type before and go to the args and paste below code.

Between arguments variable add the code


'capabilities' => array( 'create_posts' => false, ),
  
    

example add between args variable.

    $args = array(
        'label'               => __( 'blogs', 'twentytwentyone' ),
        'description'         => __( 'Movie news and reviews', 'twentytwentyone' ),
        'labels'              => $labels,        
        'supports'            => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'revisions', 'custom-fields', ),       
        'taxonomies'          => array( 'genres' ),        
        'hierarchical'        => false,
        'public'              => true,
        'show_ui'             => true,
        'show_in_menu'        => true,
        'show_in_nav_menus'   => true,
        'show_in_admin_bar'   => true,
        'menu_position'       => 5,
        'can_export'          => true,
        'has_archive'         => true,
        'exclude_from_search' => false,
        'publicly_queryable'  => true,
        'capability_type'     => 'post',
        'show_in_rest' => true,
        'capabilities' => array( 'create_posts' => false,    ),
  
    );

Capabilities is option to hide the add new option from custom post type.

removed custom post type add new option

Now we follow custom method using CSS to hide the add new option form custom post type.

Second Method:-

Go to your active child theme or parent theme and open functions.php file and paste below code for hide Add new option  from Custom post type.

//How to disable custom post type add new post pragmatically
function hrtechpro_disable_new_posts() {
    // Hide sidebar link
    global $submenu;
    unset($submenu['edit.php?post_type=blogs'][10]);

    // Hide link on listing page
    if (isset($_GET['post_type']) && $_GET['post_type'] == 'blogs') {
        echo '<style type="text/css">
        #wpbody-content .wrap a.page-title-action { display:none; }
        </style>';
    }
}
add_action('admin_menu', 'hrtechpro_disable_new_posts');

//How to disable custom post type add new post pragmatically

Don’t forgot to change the blog slug to you have created custom post type slug

hide add new option from custom post type

This is all about hide ad new option form wordpress CPT

If you have any query please comment in below comment section, we have ping back for the same as soon as possible.

If you have any suggestion or idea to improve us, please make comment below on comment section, always welcome your suggestions.

If this article found you useful share it to those who are in need of this.

Sharing is caring.

How to check the root path of the server?

Discover More

Subscribe
Notify of
0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments