The media_row_actions WordPress PHP filter allows you to modify the action links for each attachment in the Media list table.
Usage
add_filter('media_row_actions', 'your_custom_function', 10, 3); function your_custom_function($actions, $post, $detached) { // your custom code here return $actions; }
Parameters
$actions
(string[]): An array of action links for each attachment. Default ‘Edit’, ‘Delete Permanently’, ‘View’.$post
(WP_Post): WP_Post object for the current attachment.$detached
(bool): Whether the list table contains media not attached to any posts. Default true.
More information
See WordPress Developer Resources: media_row_actions
Examples
Add a custom link to each attachment
This example adds a “Download” link to each attachment in the Media list table.
add_filter('media_row_actions', 'add_download_link', 10, 3); function add_download_link($actions, $post, $detached) { $actions['download'] = '<a href="' . wp_get_attachment_url($post->ID) . '">Download</a>'; return $actions; }
Remove the “View” link for all attachments
This example removes the “View” link for each attachment in the Media list table.
add_filter('media_row_actions', 'remove_view_link', 10, 3); function remove_view_link($actions, $post, $detached) { unset($actions['view']); return $actions; }
Rename the “Edit” link for all attachments
This example renames the “Edit” link to “Modify” for each attachment in the Media list table.
add_filter('media_row_actions', 'rename_edit_link', 10, 3); function rename_edit_link($actions, $post, $detached) { $actions['edit'] = str_replace('Edit', 'Modify', $actions['edit']); return $actions; }
Add a custom link based on the attachment type
This example adds a custom link to each image attachment in the Media list table.
add_filter('media_row_actions', 'add_custom_link_for_images', 10, 3); function add_custom_link_for_images($actions, $post, $detached) { if (wp_attachment_is_image($post->ID)) { $actions['custom'] = '<a href="#">Custom Action</a>'; } return $actions; }
Add a custom link for attachments not attached to any posts
This example adds a “Custom Action” link to each attachment in the Media list table that is not attached to any posts.
add_filter('media_row_actions', 'add_custom_link_for_detached', 10, 3); function add_custom_link_for_detached($actions, $post, $detached) { if ($detached) { $actions['custom'] = '<a href="#">Custom Action</a>'; } return $actions; }