Exciting News! Flipper Code is now WePlugins! Same commitment to excellence, brand new identity.

How to use post_row_actions filter in WordPress

Sandeep Kumar Mishra
Sandeep Kumar Mishra
June 29, 2023
5 minutes read

post_row_actions Filter

Filters the array of row action links on the Posts list table.

 apply_filters('post_row_actions', string[] $actions, WP_Post $post) 
Description

The filter is evaluated only for non-hierarchical post types.

This hook is used for generating post row action for custom post type. Also, your Custom Post Type must be non-hierarchical. ‘hierarchical’ => false when declaring your CPT with register_post_type(‘MyCustomPostType’…).

To use this filter for a specific post type, the best way is to use the post_row_actions filter and then test against the passed in $post->post_type.

    function weplugins_my_duplicate_post_link($actions, $post) {
        if ($post->post_type == 'myposttype') {
            $actions['duplicate'] = '<a title="" href="#" rel="permalink">Duplicate</a>';
        }
        return $actions;
    }
    add_filter('post_row_actions', 'weplugins_my_duplicate_post_link', 10, 2);
    
Parameters
  • $actions: (string[]) An array of row action links. Defaults are ‘Edit’, ‘Quick Edit’, ‘Restore’, ‘Trash’, ‘Delete Permanently’, ‘Preview’, and ‘View’.
  • $post: (WP_Post) Post object.
Live Examples

Example 1: Basic Hook Implementation

Here’s a simple implementation of the post_row_actions filter:

    $actions = apply_filters('post_row_actions', $actions, $post);

    if (!empty($actions)) {
        // everything has led up to this point...
    }
    

Example 2: Adding a Hook Callback

This example demonstrates how to add a callback to the hook:

    add_filter('post_row_actions', 'weplugins_modify_list_row_actions', 10, 2);
    function weplugins_modify_list_row_actions($actions, $post) {
        // Check for your post type.
        if ($post->post_type == "my_custom_post_type") {
            // Build your links URL.
            $url = admin_url('admin.php?page=mycpt_page&post=' . $post->ID);
            // Maybe put in some extra arguments based on the post status.
        }
    }
    

Example 3: Removing a Hook Callback

Use the following method to remove a callback from the hook:

    remove_filter('post_row_actions', 'weplugins_filter_post_row_actions', 10, 2);
    

Access Premium WordPress Plugins

Contact Us

If you need customization or further assistance, feel free to Contact Us.

Sandeep Kumar Mishra

Sandeep Kumar Mishra

Sandeep Kumar Mishra writes about WordPress and Artificial Intelligence, offering tips and guides to help you master your website and stay updated with the latest tech trends.

Explore the latest in WordPress

Trying to stay on top of it all? Get the best tools, resources and inspiration sent to your inbox every Wednesday.