Hide Add New and Trash links for non-admin users for a specified custom post type

Only admins should see the Add New button and Trash links on the post listing page and individual post edit screen (so that other roles can still edit the posts in question).

They can be hid with the following code (note this must be added to the theme’s functions.php file, not to Toolset > Settings > Custom Code), editing the slug of the custom post type (“thing” in the example):

/**
 * Remove Add New and Trash/Delete capabilities
 */
function tssupp_re_register($args, $type) {

	if ( $type == 'thing' ) {

		$args['capabilities'] = array(
			'create_posts' => 'administrator',
			'delete_posts' => 'administrator',
			'delete_others_posts' => 'administrator',
			'delete_private_posts' => 'administrator',
			'delete_published_posts' => 'administrator',
		);
		$args['map_meta_cap'] = true;

	}

	return $args;
}
add_filter('register_post_type_args', 'tssupp_re_register', 20, 2);

Let us know if this snippet is not working for you:

This snippet doesn’t work
0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments