Reputation: 13
I have a custom post type named "jxta_home". I have removed add new button from the submenu and edit page by using the following code-
<?php
function disable_new_posts() {
global $submenu;
unset($submenu['edit.php?post_type=jxta_home'][10]);
// Hide link on listing page
if (isset($_GET['post_type']) && $_GET['post_type'] == 'jxta_home') {
echo '<style type="text/css">
.page-title-action, .submitdelete { display:none; }
</style>';
}
}
But the add new button is still showing on the inner editor page. I want to remove it from there too. How can I remove it from the inner editor page?
Upvotes: 0
Views: 3250
Reputation: 11
You can change the capabilities
Register the post type with the map_meta_cap and create_posts as true;
$args = array(
'label' => __( 'Custom Post Type', 'text_domain' ),
'description' => __( 'Custom Post Type', 'text_domain' ),
'capability_type' => 'custom_post_type',
'map_meta_cap'=>true,
'capabilities' => array(
'create_posts' => true
)
);
register_post_type( 'custom_post_type', $args );
Then You can change the capabilities adding an action on load-post.php tag.
add_action('load-post.php', 'remove_add_button');
function remove_add_button() {
if( get_post_type($_GET['post']) == 'MY-CUSTOM-POST-TYPE' ) {
global $wp_post_types;
$wp_post_types['MY-CUSTOM-POST-TYPE']->map_meta_cap = true;
$wp_post_types['MY-CUSTOM-POST-TYPE']->cap->create_posts = false;
}
}
Upvotes: 0
Reputation: 3514
There is two option once is with css and another is will coding.
Option 1 :
function disable_new_posts() {
// Hide sidebar link
global $submenu;
unset($submenu['edit.php?post_type=jxta_home'][10]);
// Hide link on listing page
if (isset($_GET['post_type']) && $_GET['post_type'] == 'jxta_home') {
echo '<style type="text/css">
#favorite-actions, .add-new-h2, .tablenav { display:none; }
</style>';
}
}
add_action('admin_menu', 'disable_new_posts');
Option 2 :
You disable the add new capabilities while passing the parameter in the register post type.
The parameter is :
create_posts' => false
Assuming you have the code like below :
$args = array(
'label' => __( 'Custom Post Type', 'text_domain' ),
'description' => __( 'Custom Post Type', 'text_domain' ),
'capability_type' => 'custom_post_type',
'capabilities' => array(
'create_posts' => false
)
);
register_post_type( 'custom_post_type', $args );
Upvotes: 2