The WPFolks app is out on iPhone and Android. Free, no ads. Download on the App Store Get it on Google Play
Skip to main content
Login Join
Snippet · PHP

Add a Duplicate Post Link to the WordPress Admin Posts List

Shared by Amit Dholiya · October 26, 2026

5 views
Back to Snippets

Steps

  1. Add the PHP code to your child theme’s functions.php file or a PHP snippets plugin.

  2. Activate the snippet.

  3. Go to WordPress Admin → Posts → All Posts.

  4. Hover over a post and click Duplicate.

Hook Used

  • post_row_actions — Adds the Duplicate link to each post.

  • admin_post_custom_duplicate_post — Handles the duplication request securely.

Type: WordPress Admin Productivity

Output: Clicking Duplicate creates a new draft containing the original post’s title, content, and excerpt, then opens the draft for editing.

Note: This basic version does not copy featured images, categories, tags, or custom fields. Review the draft before publishing it.

function custom_add_duplicate_post_link( $actions, $post ) {
    if (
        ! current_user_can( 'edit_posts' ) ||
        ! current_user_can( 'edit_post', $post->ID ) ||
        'trash' === $post->post_status
    ) {
        return $actions;
    }

    $url = wp_nonce_url(
        admin_url( 'admin-post.php?action=custom_duplicate_post&post=' . $post->ID ),
        'custom_duplicate_post_' . $post->ID
    );

    $actions['duplicate'] = '<a href="' . esc_url( $url ) . '">Duplicate</a>';

    return $actions;
}
add_filter( 'post_row_actions', 'custom_add_duplicate_post_link', 10, 2 );

function custom_duplicate_post_handler() {
    $post_id = isset( $_GET['post'] ) ? absint( $_GET['post'] ) : 0;

    check_admin_referer( 'custom_duplicate_post_' . $post_id );

    if ( ! current_user_can( 'edit_post', $post_id ) ) {
        wp_die( 'You are not allowed to duplicate this post.' );
    }

    $post = get_post( $post_id );

    if ( ! $post || 'trash' === $post->post_status ) {
        wp_die( 'Invalid post.' );
    }

    $new_post_id = wp_insert_post(
        array(
            'post_title'   => $post->post_title . ' (Copy)',
            'post_content' => $post->post_content,
            'post_excerpt' => $post->post_excerpt,
            'post_status'  => 'draft',
            'post_type'    => $post->post_type,
            'post_author'  => get_current_user_id(),
        ),
        true
    );

    if ( is_wp_error( $new_post_id ) ) {
        wp_die( esc_html( $new_post_id->get_error_message() ) );
    }

    wp_safe_redirect( admin_url( 'post.php?action=edit&post=' . $new_post_id ) );
    exit;
}
add_action( 'admin_post_custom_duplicate_post', 'custom_duplicate_post_handler' );

Tested on

WordPress 6.8

Reported by the author on October 26, 2026. WPFolks has not verified this.

Not tested against WordPress 7.1.4. It may still work.

Know a different way to do this? Add your approach as a variation so folks can compare them side by side.
Submit a variation

0 comments

Proudly supported by