This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.
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)
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);
- $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.
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);
If you need customization or further assistance, feel free to Contact Us.
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.