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 my_duplicate_post_link($actions, $post)
{
    if ($post->post_type=='myposttype')
    {
        $actions['duplicate'] = '<a href="#" title="" rel="permalink">Duplicate</a>';
    }
    return $actions;
}
add_filter('post_row_actions', '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 Example

To run the hook, copy the example below.

$actions = apply_filters( 'post_row_actions',$actions, $post ); 
                         
if ( !empty( $actions ) ) { 
                         
   // everything has led up to this point... 
                         
} 
  

The following example is for adding a hook callback.

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

To remove a hook callback, use the example below.
// remove the filter

 remove_filter( 'post_row_actions', 'filter_post_row_actions', 10, 2 );
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.