Get started with 33% off your first certification using code: 33OFFNEW

How to disable "Add New" against a WordPress post type

2 min read
Published on 24th November 2023

Blog Image

WordPress's flexibility allows for extensive customization, including tweaking how users interact with different post types. There are scenarios where you might want to disable the "Add New" button for a specific post type. This could be to maintain control over content creation, limit user roles, or manage custom data entries. Let's walk through the process of disabling the "Add New" option for a particular post type in WordPress.

Understanding the Use Case

Before diving in, it's important to understand why you might need to disable this feature. Common reasons include:

  • Content Control: For custom post types that shouldn't be frequently updated or added (like a specific set of static pages).
  • User Role Management: Limiting what certain user roles can do in your WordPress backend.
  • Custom Data Management: When entries for a custom post type are managed through external sources or specific processes.

Method 1: Using the register_post_type Function

If you are registering a custom post type, you can directly set the 'Add New' feature to false in the register_post_type function.

In your theme's functions.php file or in your plugin file, modify the register_post_type call:

register_post_type('custom_post_type', array(
    'public' => true,
    'show_in_menu' => true,
    'capability_type' => 'post',
    // Other arguments...
    'capabilities' => array(
        'create_posts' => false, // Removes the ability to add new
    ),
    'map_meta_cap' => true, // Required for the above 'capabilities' to work
));

This method is effective for custom post types and provides a high level of control.

Method 2: Using CSS to Hide the Button

For a quick fix, particularly if you are dealing with a default post type, you can hide the "Add New" button using CSS.

  1. Identify the Post Type: Find the post type's name by looking at the URL in the admin dashboard. For example, post_type=book.

  2. Add Custom CSS: Go to "Appearance" > "Customize" > "Additional CSS" and add:

.post-type-book .page-title-action {
    display: none;
}

Replace book with your post type.

While this method hides the button, it doesn't completely remove the functionality and can be bypassed by direct URL access.

Method 3: Using a Plugin

If you prefer not to dive into code, various plugins allow you to manage the capabilities and roles within WordPress, such as "Members" or "User Role Editor." These plugins let you define capabilities for different roles, including the ability to add new posts for specific post types.

Testing and User Roles

After implementing your chosen method, test it by:

  • Logging in with different user roles to ensure the "Add New" button is disabled as expected.
  • Trying to access the "Add New" page directly via URL to check if the restriction is in place.