Is there any way to disable the option of adding a new post under a Custom Post Type in WordPress (3.0)? I’ve looked into labels and arguments but can’t find anything that would resemble such a feature.
Leave a Reply
You must be logged in to post a comment.
There is a meta capability
create_posts
that is documented here and is used by WordPress to check before inserting the various ‘Add New’ buttons and links. In your custom post type declaration, addcapabilities
(not to be confused withcap
) and then set it tofalse
as below.You’ll probably want to set
map_meta_cap
totrue
as well. Without it, you won’t be able to access the posts’ editing pages anymore.The combinations of the solutions above work in hiding the links (although someone could quite easily type the URL in directly.
The solution mentioned @3pepe3 relies on
get_post_type()
which will only work if there is already a post in the listing. If there are no posts, the function will not return anything, and the “Add New” link will be available. An alternative method:EDIT: To prevent direct access if someone types the URL in themselves: https://wordpress.stackexchange.com/a/58292/6003
WordPress Networks:
I found that Seamus Leahy’s answer doesn’t workif you are logged in as a super admin of the network, it doesn’t matter if the user doesn’t have the capability, mapped or otherwise, when current_user_can($cap) is called by the CMS. By digging into the core I found you can do the following.The accepted answer hides the menu item, but the page is still accessible.In wordpress and for all the post types there is the capability create_posts. This capability is used in several core files :
So if you really want to disable this feautere you must do it per role and per post type.
I use the great plugin “User Role Editor” to manage the capabilities per role.
But what about the capability create_posts? Well this capability is not mapped and also create_posts is equal to create_posts so we should fix this and map the capability per post type.
So you can add this piece of code in your functions.php and the you can manage this capability.
So here we are not hiding or removing menu elements… here we are removing the capability for users (including xmlrpc requests).
The action was init and not admin_init or anything else because init at priority 100 prevents the display of “add new” on admin bar, sidebar, etc (in all the wp interface).
Disable creating new post for registered post-types: (example for
post
andpage
)@ Staffan Estberg,
This is best way to hide the Add New or Create New button in custom postypes
It disable to create new post in custom post types both side in admin menu and above the list of post type.
I found this simplest way for this. Just ad this code into themeâs
function.php
.As the question is ‘how to disable add-new button on custom post type’, and not ‘how to restrict user editing custom post types’, in my opinion the answer should be purely hiding the buttons with css, by adding this to the functions.php file :