# "Copy Link" Action in Admin Lists

> Adds a "Copy link" action under each published post and page in admin lists that copies its public URL to the clipboard in one click, for sharing in chats and emails.

- Type: PHP
- Runs: Admin only
- Category: [Admin](https://wpide.com/library/category/admin/)
- Tags: row-actions, clipboard, links
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/admin-copy-link-row-action/

## Code

```php
$wpide_copy_link_action = function ( $actions, $post ) {
    if ( 'publish' === $post->post_status && is_post_type_viewable( $post->post_type ) ) {
        $actions['wpide_copy_link'] = sprintf(
            '<button type="button" class="button-link wpide-copy-link" data-url="%s">Copy link</button>',
            esc_attr( get_permalink( $post ) )
        );
    }
    return $actions;
};
add_filter( 'post_row_actions', $wpide_copy_link_action, 10, 2 );
add_filter( 'page_row_actions', $wpide_copy_link_action, 10, 2 );

add_action( 'admin_footer-edit.php', function () {
    ?>
    <script>
    document.addEventListener( 'click', function ( event ) {
        var button = event.target.closest( '.wpide-copy-link' );
        if ( ! button ) { return; }
        var url = button.dataset.url;
        var done = function () {
            var label = button.textContent;
            button.textContent = 'Copied!';
            setTimeout( function () { button.textContent = label; }, 1500 );
        };
        if ( navigator.clipboard && window.isSecureContext ) {
            navigator.clipboard.writeText( url ).then( done );
        } else {
            window.prompt( 'Copy this link:', url );
        }
    } );
    </script>
    <?php
} );
```

## Notes

Uses the browser clipboard; very old browsers fall back to a prompt with the URL selected.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find ""Copy Link" Action in Admin Lists" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
