1

enter image description here

I have been adding a post type to my theme, how do I hide/disable the Move to trash button? Here is my code so far:

$labels = array(
        'name'                       => _x( 'Inhoud', 'taxonomy general name' ),
        'singular_name'              => _x( 'Inhoud', 'taxonomy singular name' ),
        'search_items'               => __( 'Zoek Inhoud' ),
        // 'popular_items'              => __( 'Popular Writers' ),
        'all_items'                  => __( 'Alle Inhoud' ),
        'parent_item'                => null,
        'parent_item_colon'          => null,
        'edit_item'                  => __( 'Wijzig Inhoud' ),
        'update_item'                => __( 'Update Inhoud' ),
        'add_new_item'               => __( 'Toevoegen Nieuwe Inhoud' ),
        // 'new_item_name'              => __( 'Nieuwe Evenement Naam' ),
        // 'separate_items_with_commas' => __( 'Separate writers with commas' ),
        // 'add_or_remove_items'        => __( 'Add or remove writers' ),
        // 'choose_from_most_used'      => __( 'Choose from the most used writers' ),
        'not_found'                  => __( 'Geen inhoud gevonden.' ),
        'menu_name'                  => __( 'Inhoud' ),
    );

    $args = array(
        'hierarchical'      => false,
        'labels'            => $labels,
        'show_ui'           => true,
        //'show_admin_column'     => true,
        //'update_count_callback' => '_update_post_term_count',
    'menu_position'     => 7,
    'menu_icon'         => 'dashicons-admin-post',
    'show_in_menu'      => true,
    'show_in_nav_menus' => false,
    'show_in_admin_bar' => false,
        // 'query_var'         => true,
        // 'rewrite'           => array( 'slug' => 'inhoud' ),
    'capabilities'      => array( 
                            'create_posts'  => 'do_not_allow',
                            //'edit_post'   => 'true',
                            //'delete_posts'   => 'do_not_allow'
                          ),
    'supports'          => array( ),
    'map_meta_cap'      => array('delete_post' => false),
    'has_archive'       => true,
    'public'            => true
    );

    register_post_type( 'inhoud', $args );
2
  • 1
    Has this question been resolved? Did my answer help? Aug 28, 2016 at 22:06
  • I've forgot to respond on this question, I gave you some points for a solution ;-) But went for the other one.
    – poashoas
    Sep 21, 2016 at 22:04

2 Answers 2

2

You can hide move to trash button via adding css in the admin area. Try following code in functions.php file:

function my_custom_admin_styles() {
?>
    <style type="text/css">
      .post-type-inhoud form #delete-action{
           display:none;
       }
     </style>
<?php
}
add_action('admin_head', 'my_custom_admin_styles');
3

Tested out the code that was provided by user3888958, but didn't work for me. here's my own version which hide the Move to Trash link:

add_action( 'admin_head', 'wpse_237305_disable_trash' );

function wpse_237305_disable_trash() {
    global $pagenow;

    if ( $pagenow == 'post.php' ) {
        ?>
        <script type="text/javascript">
            jQuery( document ).ready( function( $ ) {
                $( '#delete-action' ).remove();
            } );
        </script>
        <?php
    }
}

Result

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.