Using WordPress ‘post_row_actions’ PHP filter

The post_row_actions WordPress PHP filter allows you to modify the array of row action links on the Posts list table for non-hierarchical post types.

Usage

add_filter('post_row_actions', 'your_custom_function', 10, 2);

function your_custom_function($actions, $post) {
    // your custom code here
    return $actions;
}

Parameters

  • $actions (array): An array of row action links. Defaults are ‘Edit’, ‘Quick Edit’, ‘Restore’, ‘Trash’, ‘Delete Permanently’, ‘Preview’, and ‘View’.
  • $post (WP_Post): The post object.

More information

See WordPress Developer Resources: post_row_actions

Examples

Add a custom action link to the Posts list table.

add_filter('post_row_actions', 'add_custom_action_link', 10, 2);

function add_custom_action_link($actions, $post) {
    $actions['custom_link'] = '<a href="http://example.com">Custom Link</a>';
    return $actions;
}

Remove the ‘Quick Edit’ link from the Posts list table.

add_filter('post_row_actions', 'remove_quick_edit_link', 10, 2);

function remove_quick_edit_link($actions, $post) {
    unset($actions['inline hide-if-no-js']);
    return $actions;
}

Change the URL of the ‘Preview’ link in the Posts list table.

add_filter('post_row_actions', 'change_preview_link', 10, 2);

function change_preview_link($actions, $post) {
    $actions['view'] = '<a href="http://example.com/preview/' . $post->ID . '">Preview</a>';
    return $actions;
}

Add a custom action link for specific post types

Add a custom action link only for a specific post type in the Posts list table.

add_filter('post_row_actions', 'add_custom_action_for_specific_post_type', 10, 2);

function add_custom_action_for_specific_post_type($actions, $post) {
    if ($post->post_type == 'your_post_type') {
        $actions['custom_link'] = '<a href="http://example.com">Custom Link</a>';
    }
    return $actions;
}

Reorder the action links in the Posts list table.

add_filter('post_row_actions', 'reorder_action_links', 10, 2);

function reorder_action_links($actions, $post) {
    $new_actions = array();
    $new_actions['view'] = $actions['view'];
    $new_actions['edit'] = $actions['edit'];
    $new_actions['trash'] = $actions['trash'];
    return $new_actions;
}

END