Using WordPress ‘page_row_actions’ PHP filter

The page_row_actions WordPress PHP filter modifies the array of row action links on the Pages list table. It is evaluated only for hierarchical post types.

Usage

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

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

    return $actions;
}

Parameters

  • $actions (string[]): 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: page_row_actions

Examples

Add a custom action link to the Pages list table row actions.

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

function add_custom_action_link($actions, $post) {
    $actions['custom_action'] = '<a href="https://example.com/?page_id=' . $post->ID . '">Custom Action</a>';
    return $actions;
}

Remove the ‘Quick Edit’ action link from the Pages list table row actions.

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

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

Rearrange the action links in the Pages list table row actions.

add_filter('page_row_actions', 'rearrange_action_links', 10, 2);

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

Remove the ‘Trash’ action link from the Pages list table row actions for specific pages.

add_filter('page_row_actions', 'remove_trash_link_for_specific_pages', 10, 2);

function remove_trash_link_for_specific_pages($actions, $post) {
    if ($post->ID == 42) {
        unset($actions['trash']);
    }
    return $actions;
}

Add a custom action link based on post status

Add a custom action link to the Pages list table row actions based on the post status.

add_filter('page_row_actions', 'add_custom_action_link_based_on_status', 10, 2);

function add_custom_action_link_based_on_status($actions, $post) {
    if ($post->post_status == 'draft') {
        $actions['custom_action'] = '<a href="https://example.com/?draft_page_id=' . $post->ID . '">Custom Draft Action</a>';
    }
    return $actions;
}