admin管理员组文章数量:1122832
I have many custom post types that need the Add [custom post type] feature but I have a custom post type of "About" and I do not need to "Add New" about to the about custom post type. So I want to remove the button on top that says "Add About"
This is what I mean:
Any idea how I can remove that?
I have many custom post types that need the Add [custom post type] feature but I have a custom post type of "About" and I do not need to "Add New" about to the about custom post type. So I want to remove the button on top that says "Add About"
This is what I mean:
Any idea how I can remove that?
Share Improve this question asked Nov 22, 2014 at 9:32 Lucas SantosLucas Santos 2652 gold badges6 silver badges15 bronze badges5 Answers
Reset to default 7Please refer below :
function disable_new_posts() {
// Hide sidebar link
global $submenu;
unset($submenu['edit.php?post_type=CUSTOM_POST_TYPE'][10]);
// Hide link on listing page
if (isset($_GET['post_type']) && $_GET['post_type'] == 'CUSTOM_POST_TYPE') {
echo '<style type="text/css">
#favorite-actions, .add-new-h2, .tablenav { display:none; }
</style>';
}
}
add_action('admin_menu', 'disable_new_posts');
A prettier solution would be to disable the capability of creating a custom_post_type:
Simply pass the the parameter 'create_posts' => 'do_not_allow',
in the capabilities array when calling register_post_type
.
$args = array(
'label' => __( 'Custom Post Type', 'text_domain' ),
'description' => __( 'Custom Post Type', 'text_domain' ),
'labels' => $labels,
'supports' => array( ),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'map_meta_cap' => true,
'capabilities' => array(
'create_posts' => 'do_not_allow'
)
);
register_post_type( 'custom_post_type', $args );
Then, if you just want to remove Add New and you are not using custom_post_type
, you should't use 'capability_type' => 'custom_post_type'
. You'd better to remove this code. Good luck :)
So, the demo is below:
array(
'labels' => $member_labels,
'has_archive' => true,
'public' => true,
'hierarchical' => true, // like page
'rewrite' => array('slug' => 'member_pages'),
'supports' => array(
'title',
'editor',
'excerpt',
'custom-fields',
'thumbnail',
'page-attributes',
),
'taxonomies' => array('post_tag', 'cm_club'),
// 'capability_type' => 'custom_post_type',
'capabilities' => array(
'create_posts' => false,
),
'map_meta_cap' => true,
)
Edited @TompaLompa's answer as it was incomplete. Adding create_posts => false
won't work if map_meta_cap
is not set to true
.
Not setting this parameter (or setting it to false
) will disable editing of the post type too. This is because you would need to add edit_post
capability to each user role in order to add AND edit your post type.
Setting this parameter will use WP internal default meta capability handling and make it work for you if you don't need more finer control over role capabilities then the default WP ones.
Best way i felt is install add-admin-javascript plugin and activate it then go to settings and add javascript write this code in last box
$('.wrap .wp-heading-inline').remove();
$('.wrap .page-title-action').remove();
$('#wp-admin-bar-new-content').remove();
本文标签: phpHow can I remove the quotAdd Newquot button in my custom post type
版权声明:本文标题:php - How can I remove the "Add New" button in my custom post type? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736288981a1928208.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论