If you can’t think of a single reason why anyone would need to duplicate their pages or posts in WordPress, you probably never had to redesign your site. If you did, you’d know just how useful duplicating pages or posts can be.

In this article, we’re going to show you how to duplicate a page in WordPress, the benefits of creating duplicate pages or posts and teach you three ways to do it: manually, using a plugin and using code.

Here’s what we’ll discuss:

  • Why and When to Duplicate WordPress Pages or Posts?
  • How to Duplicate a WordPress Page Manually?
  • Duplicating Pages or Posts Using a Plugin
  • Duplicating Pages or Posts Using Code

repurposing old content, and it’s much better than the simple copy/paste.

“What’s wrong with copying and pasting the content in a new draft to use it again after you make the changes?” you might ask. Well, of course, that would work but it would be pretty time-consuming, for one thing.

Also, and more importantly, it might affect all your previous SEO efforts, and, consequently, damage your page rank. This is because, when you simply copy the content and paste it on a page that you have redesigned, everything you’ve done SEO-wise, as well as your featured image, page templates and other related data, would be lost.

Also, duplicate pages are useful for situations when you just want to tweak a few things in your page design, for example, and compare it with the old version to see which one works better. This is particularly handy for when you’re redesigning your website and need to see how your content will fit your new design elements.

As you can see, there are many situations in which creating a clone or a duplicate of your page or post comes in handy.

Yoast Duplicate Post.

Yoast Duplicate Post

This is a neat, simple and functional plugin with over three million active installations that you can download and use for free.

Once you have installed and activated the plugin, go to your posts or pages, and you’ll notice some new options appear as you hover above the post you want to duplicate. There will be two options: Clone and New Draft.

Post options Clone and New Draft

The Clone option creates the exact duplicate of the post you want to edit or change. The duplicate will appear on top of the list of posts and, clicking on it, you will be able to edit it the usual way.

The Clone option

New Draft, on the other hand, creates a clone of the page and then opens the page/post editor right away. Once you’ve made all the necessary changes to the post, click on Publish and review it live.

New Draft option

And that’s really all there is to it. Once you no longer need the clones, you can delete them quickly by clicking on the Trash link that reveals underneath the post upon hover.

Delete post

neat function for creating duplicate posts or pages that you simply need to copy to your functions.php file:

/*
* Function for post duplication. Dups appear as drafts. User is 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!');
}
/*
* Nonce verification
*/
if ( !isset( $_GET['duplicate_nonce'] ) || !wp_verify_nonce( $_GET['duplicate_nonce'], basename( __FILE__ ) ) )
return;
/*
* get the original post id
*/
$post_id = (isset($_GET['post']) ? absint( $_GET['post'] ) : absint( $_POST['post'] ) );
/*
* and all the original post data then
*/
$post = get_post( $post_id );
/*
* if you don't want current user to be the new post author,
* then change next couple of lines to this: $new_post_author = $post->post_author;
*/
$current_user = wp_get_current_user();
$new_post_author = $current_user->ID;
/*
* if post data exists, create the post duplicate
*/
if (isset( $post ) && $post != null) {
/*
* new post data array
*/
$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
);
/*
* insert the post by wp_insert_post() function
*/
$new_post_id = wp_insert_post( $args );
/*
* get all current post terms ad set them to the new post draft
*/
$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);
}
/*
* duplicate all post meta just in two SQL queries
*/
$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);
}
/*
* finally, redirect to the edit post screen for the new draft
*/
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' );
/*
* Add the duplicate link to action list for post_row_actions
*/
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 );
to join this conversation on GitHub. Already have an account? Sign in to comment

You can do it directly on your server using an FTP client of your choice, but we suggest you simply use the WordPress file editor.

Note here that this code is written for duplicating WordPress posts. If you want to duplicate pages as well, you need to change the last line in the snippet so that, instead of ‘post_raw_actions’ it says ‘page_raw_actions’.

After you have entered the code in your functions.php file, go to your dashboard where your pages and posts are listed (All Posts or All Pages). If everything worked fine, there will be a new option available underneath each of the posts or pages, saying simply Duplicate. Clicking on it will create a clone of that particular page or post, just as it would if you were using a plugin.

New Themes

VIEW COLLECTION

Chaises

Chaises

Furniture WooCommerce WordPress Theme

Sonora

Sonora

Photography WordPress Theme

Exon

Exon

Gaming and eSports WordPress Theme

Final Thoughts

As you can see, creating duplicate WordPress pages or posts is actually a piece of cake, whether you’re doing it manually, using a plugin or opting for code instead. We are sure you’ll find this option more than convenient in many situations.

Now that you know how to duplicate a page in WordPress, just remember to clean up the unused duplicate posts once in a while – clutter is never a good thing for a website. Also, if you intend to use code to duplicate posts, make sure your website is backed up, as it should be whenever you’re editing WordPress files.

Similar Posts