Remove Quick Edit and Related Row Actions for Specific WordPress Post Types

Quick Edit is a small but very useful feature in the WordPress post list. It lets you edit certain post properties quickly, such as title, slug, categories, and tags. Custom post types inherit this behavior too, but for some post types Quick Edit is unnecessary or even confusing.

For example, imagine a custom post type called Message that stores inquiries submitted from the front end. In that case, you might want customer service staff to view those entries but not edit them. Removing Quick Edit is one part of that workflow.

Remove Quick Edit for a specific post type

The following code removes the Quick Edit row action from the target post type:

add_filter( 'post_row_actions', function ( $actions = [], $post = null ) {
    // Return early if this is not the target post type.
    if ( ! in_array( get_post_type( $post ), [ 'message' ], true ) ) {
        return $actions;
    }

    // Remove the Quick Edit action.
    if ( isset( $actions['inline hide-if-no-js'] ) ) {
        unset( $actions['inline hide-if-no-js'] );
    }

    return $actions;
}, 10, 2 );

Default row actions in the WordPress post list

The example above works by filtering post_row_actions and modifying the $actions array. If you want to disable other actions as well, it helps to know the default action keys that WordPress uses:

[
    'view',
    'edit',
    'inline hide-if-no-js',
    'delete',
    'trash',
    'untrash',
]

Using those keys, you can replace the action name in the example above and remove whichever row action you do not want to expose for that post type.

Keep in mind that some plugins add their own custom row actions. In those cases, search the plugin code for post_row_actions to find and remove the extra links as needed.

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *