This tutorial will show you multiple ways to duplicate post and page in WordPress, using plugins, edit code snippet or manually.
Why WordPress Page and Post Duplication Is Essential
We briefly listed out reasons why you might want to duplicate your pages and posts in WordPress
1. Editing a page on a live site
When you need to make edits to a page on your live WordPress website. You can duplicate the existing page, making all the needed edits to the duplicate. And then replacing the original page with the duplicate. If you do this, the chances of breaking things are greatly minimized.
Reason 2: Creating multiple, similar page
When you need to create several product pages with a similar design and layout. To save time and improve efficiency, you simply create a page that will serve as a template. Then duplicate it as many times as the number of products you have.
Reason 3: Maintaining design structure on the site
When you want your pages and posts to maintain the same design across. You can create an original version, and then duplicating it as many times as you wish. And in turn, making changes across the duplicates.
1. WordPress Duplicate Page/Post Plugin
Using a plugin is the easiest way to duplicate a WordPress post. We recommend Duplicate Page plugin.
To get started, install and activate this free plugin by going to Plugins → Add New and searching for it by name: Duplicate Post
Go to Settings > Duplicate Post in your WordPress dashboard where you can choose the elements you’d like to copy and some custom options for the transfer process:
Then, navigate to All Posts or All Pages pages within WordPress. And hover over your chosen entry and click Duplicate This:
Just duplicate the page without needing to edit it, you click Clone. Note that if the original post is live – that is, has been published – the duplicate will also go live.
One the other hand, clicking New Draft will duplicate the page, and then open it in editor mode. After editing, it will go live.
2. Add Code to Your functions.php File
First, you should run a child theme so that you can retain your changes when your theme needs updating. Next, open your functions.php file using either File Transfer Protocol (FTP) or WordPress’ built-in theme editor.
Here’s the code snippet that you’ll need to add to one of those areas:
/*
* This code duplicates a WordPress page. The duplicate page will appear as a draft and the user will be redirected to the edit screen.
*/
function rd_duplicate_post_as_draft(){
global $wpdb;
if (! ( isset( $_GET['post']) || isset( $_POST['post']) || ( isset($_REQUEST['action']) && 'rd_duplicate_post_as_draft' == $_REQUEST['action'] ) ) ) {
wp_die('No post to duplicate has been supplied!');
}
if ( !isset( $_GET['duplicate_nonce'] ) || !wp_verify_nonce( $_GET['duplicate_nonce'], basename( __FILE__ ) ) )
return;
$post_id = (isset($_GET['post']) ? absint( $_GET['post'] ) : absint( $_POST['post'] ) );
$post = get_post( $post_id );
$current_user = wp_get_current_user();
$new_post_author = $current_user->ID;
if (isset( $post ) && $post != null) {
$args = array(
'comment_status' => $post->comment_status,
'ping_status' => $post->ping_status,
'post_author' => $new_post_author,
'post_content' => $post->post_content,
'post_excerpt' => $post->post_excerpt,
'post_name' => $post->post_name,
'post_parent' => $post->post_parent,
'post_password' => $post->post_password,
'post_status' => 'draft',
'post_title' => $post->post_title,
'post_type' => $post->post_type,
'to_ping' => $post->to_ping,
'menu_order' => $post->menu_order
);
$new_post_id = wp_insert_post( $args );
$taxonomies = get_object_taxonomies($post->post_type); // returns array of taxonomy names for post type, ex array("category", "post_tag");
foreach ($taxonomies as $taxonomy) {
$post_terms = wp_get_object_terms($post_id, $taxonomy, array('fields' => 'slugs'));
wp_set_object_terms($new_post_id, $post_terms, $taxonomy, false);
}
$post_meta_infos = $wpdb->get_results("SELECT meta_key, meta_value FROM $wpdb->postmeta WHERE post_id=$post_id");
if (count($post_meta_infos)!=0) {
$sql_query = "INSERT INTO $wpdb->postmeta (post_id, meta_key, meta_value) ";
foreach ($post_meta_infos as $meta_info) {
$meta_key = $meta_info->meta_key;
if( $meta_key == '_wp_old_slug' ) continue;
$meta_value = addslashes($meta_info->meta_value);
$sql_query_sel[]= "SELECT $new_post_id, '$meta_key', '$meta_value'";
}
$sql_query.= implode(" UNION ALL ", $sql_query_sel);
$wpdb->query($sql_query);
}
wp_redirect( admin_url( 'post.php?action=edit&post=' . $new_post_id ) );
exit;
} else {
wp_die('Post creation failed, could not find original post: ' . $post_id);
}
}
add_action( 'admin_action_rd_duplicate_post_as_draft', 'rd_duplicate_post_as_draft' );
function rd_duplicate_post_link( $actions, $post ) {
if (current_user_can('edit_posts')) {
$actions['duplicate'] = '<a href="' . wp_nonce_url('admin.php?action=rd_duplicate_post_as_draft&post=' . $post->ID, basename(__FILE__), 'duplicate_nonce' ) . '" title="Duplicate this item" rel="permalink">Duplicate</a>';
}
return $actions;
}
add_filter( 'post_row_actions', 'rd_duplicate_post_link', 10, 2 );
add_filter( 'page_row_actions', 'rd_duplicate_post_link', 10, 2 );
Copy and paste the code into the WordPress theme editor.
Then you’ll see a new Duplicate option when you hover over a post or page.
3. Manually Duplicate Your Content to a New Page
This is manual duplication when your WordPress has a Gutenberg editor. But we don’t recommend you use this way due to its limitation.
But if you would still like to proceed manually, here’s how to.
Navigate to Posts >> All Posts
In the post list, select the post you would like to duplicate and open it. With the post opened, click on the three-dot icon at the top right corner.
Upon click, locate Copy All Content option, and click on it.
So all content of the post, including images and other media inserted into it.
Create a new post, then paste the content you had copied earlier. With that, you have a brand new duplicated post.
Conclusion
Using the plugin is the easiest way to duplicate any WordPress post or page. But if you want to keep things more lightweight and avoid installing a new plugin, you can always use your own code snippet instead. Besides, WordPress Gutenberg also gives you the option of duplicating your posts manually.