1

I have a custom post type that is created using a form on the site. I want to disable new post creation from wordpress admin. Is there a way to do that ?

2

3 Answers 3

3

There are several ways (depending on what you're trying to do):

If it's about the "publish" button

You could…

  1. …remove the capability from the targeted role with remove_cap()
  2. …remove the publish button 1)

    1) see bottom of the answer by @toscho

  3. …or the whole meta box 2)

    remove_meta_box( 'submitdiv', 'custom_post_id', 'side' );
    

    2) simplified version

If it's about the built in `post` post type

You could…

  1. …simply hide the menu entry via css or js
  2. …unset the menu entry with

    add_action( 'admin_menu', 'myprefix_adjust_the_wp_menu', 999 );
    function myprefix_adjust_the_wp_menu() {
      $page = remove_submenu_page( 'edit.php', 'post-new.php' );
      //or for custom post type 'myposttype'.
      //$page = remove_submenu_page( 'edit.php?post_type=myposttype', 'post-new.php?post_type=myposttype' );
    }
    
  3. …prevent saving at all with the per_save_post hook and $_GET['action']

  4. …do a redirect when the post-new.php is load
0
9

There is a meta capability create_posts that is not documented but is used by WordPress to check before inserting the various 'Add New' buttons and links. In your custom post type declaration, add capabilities (not to be confused with cap) and then set it to false as below.

register_post_type( 'custom_post_type_name', array(
  'capabilities' => array(
    'create_posts' => false,
  )
));
1
  • This has now changed to: ` 'capabilities' => [ 'create_posts' => 'do_not_allow' ], 'map_meta_cap' => true, ` Jul 28, 2015 at 21:16
0

@ hannit cohen,

This is best way to hide the Add New or Create New button in custom postypes

'capability_type'    => 'post',

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

        'map_meta_cap'       => true,

It disable to create new post in custom post types both side in admin menu and above the list of post type.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.