Removing Quick Edit and Related Action Links for Certain Post Types in WordPress

Quick Edit is a small feature in the WordPress post list that allows us to quickly edit certain post attributes, such as title, slug, categories, tags, etc. For CMS systems, this feature is very practical. Custom post types also inherit this feature. For some post types, this feature is useless and might even cause confusion for users. For example, if we create a post type named “Message” to receive inquiry information submitted by users on the frontend, and we want customer service only to view but not edit this information, we must remove the Quick Edit feature. We can achieve this requirement with the following code.

Removing the Quick Edit Feature for a Certain Post Type

add_filter('post_row_actions', function ($actions = [], $post = null)
{

    // If it's not the post type we need, return directly
    if (!in_array(get_post_type($post), ['message'])) {
        return $actions;
    }

    // Identify post type and remove the Quick Edit link
    if (isset($actions[ 'inline hide-if-no-js' ])) {
        unset($actions[ 'inline hide-if-no-js' ]);
    }

    // Return the links array after removing the Quick Edit operation
    return $actions;

}, 10, 2);

WordPress Default Post List Operation Functions

From the code above, we can see that this feature is actually implemented by modifying the $actions array through the post_row_actions filter. So, what elements are included in the $actions array, and which operations can we disable? By checking the WordPress source code, we found the following ones; replace the corresponding operation names in the code above with elements from the data below to disable the corresponding features.

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

Besides these, some plugins will add custom operations to the post list. We can search for post_row_actions to find custom operation features added by plugins and process them based on need.

Related Posts

Leave a Reply

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