5

Is it possible to remove the quick edit function for a custom post type?

I have 14 custom taxonomy with hundreds of terms in each and it takes too much time and resource to load all of them into the source-code of the page.

I tried to find a solution using google but most of them just hides the quick edit button, but the code is loaded in the footer by wordpress, so it doesn't really make any difference.

3 Answers 3

6

Check out the Bulk Actions page in the codex. I believe the proper action to unset is inline. This will remove the "Edit" bulk action, which is actually quick edit.

<?php
    function remove_bulk_actions( $actions ){
        unset( $actions['inline'] );
        return $actions;
    }
    add_filter('bulk_actions-custom_post_type_slug','remove_bulk_actions');
?>

As for the Quick Edit in each row, look into manage_{$post_type}_columns, as you may be able to replace the Title column with your own, and render it how you wish. There are currently no filters to remove Quick edit in the WP Posts List Table, so if the replacing of the column does not work, then you will need to create your own WP list table extension (Great tutorial).

1
  • Thanks! Alternatively, i can change the taxonomy to non-hierarchical when i'm on the post list page, because in that case its going to be an autocomplete input with ajax
    – passatgt
    Jan 4, 2013 at 15:04
12

To clarify on Eric's post the add_filter code needs to have the screenid before the custom post type slug. The most common being bulk_actions-edit-custom_post_type_slug.

Also, unset( $actions['inline'] ) does not appear to be an option.

Both unset( $actions['edit'] ) and unset( $actions['trash'] ) were all I could find.

Finally, this code removes the Bulk Options Drop Menu Items, it does not remove the "Quick Edit" option which appears while hovering over a post.

function ssp_remove_member_bulk_actions( $actions, $post ){
     unset( $actions['edit'] );
     return $actions;
}
add_filter('bulk_actions-edit-member','ssp_remove_member_bulk_actions', 10, 2);

THIS CODE Removes Quick Edit (thanks to jfacemyer)

function remove_quick_edit( $actions, $post ) { 
     unset($actions['inline hide-if-no-js']);
     return $actions;
}
add_filter('post_row_actions','remove_quick_edit',10,2);

You can also turn off:

  1. edit = unset($actions['edit']);
  2. trash = unset($actions['trash']);
  3. view = unset($actions['view']);

To remove everything from the Quick Edit hover options:

function remove_quick_edit( $actions, $post ) { 
     unset($actions['edit']);
     unset($actions['trash']);
     unset($actions['view']);
     unset($actions['inline hide-if-no-js']);
     return $actions;
}
add_filter('post_row_actions','remove_quick_edit',10,2);

Finally, you can only remove actions based on a Custom Post Type, or even user capabilities:

// Based on Post Type
if ($post->post_type=='myposttype') {
    unset($actions['edit']);
}
// Based on User Capability
if ( current_user_can('manage_options') ) {
   unset($actions['edit']);
}
2
  • adding unset($actions['inline hide-if-no-js']); to the function worked for me.
    – Matt
    Apr 5, 2021 at 21:50
  • For beginners please note you will need to add 'global $post;' before your if post type
    – James
    Aug 24, 2021 at 13:04
1

The accepted answer modifies bulk edit dropdown, not post rows.

The filter you seek is in wp-admin/includes/class-wp-posts-list-table.php, line 1342 (WordPress 5.0.2):

/**
 * Filters the array of row action links on the Posts list table.
 *
 * The filter is evaluated only for non-hierarchical post types.
 *
 * @since 2.8.0
 *
 * @param array $actions An array of row action links. Defaults are
 *                         'Edit', 'Quick Edit', 'Restore', 'Trash',
 *                         'Delete Permanently', 'Preview', and 'View'.
 * @param WP_Post $post The post object.
 */
$actions = apply_filters( 'post_row_actions', $actions, $post );

This will work:

/**
 * This filter modifies "my_post_type" post rows,
 * such as "Edit", "Quick Edit" and "Trash".
 *
 * @param $actions
 * @param $post
 *
 * @return mixed
 */
add_filter('post_row_actions', function($action, $post) {
    if ($post->post_type == 'my_post_type') {
        // Remove "Quick Edit"
        unset($actions['inline hide-if-no-js']);
    }
    return $actions;
}, 10, 2);
2
  • In your bottom example you need to add the parameter count to the add_filter function or it'll throw an error: add_filter('post_row_actions', function($action, $post) { .. }, 10, 2);
    – Gavin
    Jan 15, 2021 at 17:17
  • 1
    @Gavin Added, thanks. Jan 15, 2021 at 17:17

Your Answer

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

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