Do you want create a exact copy of your existing page or post on your WordPress website ? The this guide will help you get it done.
There might be different reasons for duplicating a post. You might need to create a newer version of the post or create multiple pages with same structure and layout.
We will show you 3 different ways to duplicate posts, pages, and custom post types, with a quick walk through of each of these methods.
Block Editor Method
Using In-built “Copy All Content” Feature of Block Builder
This method will be ideal if you like to copy just the content to another post/page on your WordPress website.
Unfortunately, this method won’t be work, if you are using a page builder like Elementor or Divi. Also it doesn’t copy taxonomies, page attributes and custom fields.
However, this is one of the Option you can consider, if you write lots of plain WordPress posts.
How to Copy – Paste Content in Block Builder
Follow these simple steps to move your content from one post to another.
- Click on ‘3 Dots’ on top right corner.
- Scroll down the menu, and click on “Copy All Content”.
- Go to the post where you would like to add the content. Click CTRL+V or CMD+V or Right Click > Paste to paste all the content from the old post.
Using a Free Plugin
Using Yoast Duplicate Post Plugin
Yoast Duplicate Post plugin allows you to create a copy of your pages or posts with a single click
Moreover, this plugin gives you flexibility over what to copy, the suffix and prefix of duplicate d post, and most importantly to provide permissions based on user roles.
How to Use Yoast Duplicate Post Plugin
Once you install and activate the plugin, Go to the post you want to create a duplicate of.
From the Top bar, hover over ‘Duplicate Post’ > Click on ‘Copy to a new Draft’
Plugin Settings
Other than making it a lot easier to create a duplicate, the plugin provides options to include and exclude the elements from copying to duplicated post/ page.
Permission to a specific role can be provided, which would useful in managing your editorial staff. And you will also be able to restrict the plugin to some specific post types.
Using Custom PHP code
Duplicate WordPress Posts/ Pages without Plugin
This method involves adding a snippet of code to functions.php file of your theme. Don’t worry if you are a beginner, We will explain you all the steps to make it work.
- Login to you WordPress Dashboard. Navigate to Appearance > Theme Editor
- From the drop-down, Select the theme that’s active.
- Select functions.php file from the sidebar menu
- Scroll to the bottom of the file and paste the following code.
/*
* Function creates post duplicate as a draft and redirects then to the edit post 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;
}
/*Adds Duplicate Link to posts*/
add_filter( 'post_row_actions', 'rd_duplicate_post_link', 10, 2 );
/*Adds Duplicate Link to pages*/
add_filter('page_row_actions', 'rd_duplicate_post_link', 10, 2);
This will create “Duplicate” link for Posts and Pages.
Alternate Methods
Notable Plugins
Apart from above methods, there are a number of plugins that can do this job seamlessly. I have picked some of the noteworthy plugins.
Let’s quickly have a look at them
Copy and Delete Posts
This is our favorite plugin, when comes to duplicating a page or post. Developed by Inisev, It gives the cleanest way to create and manage duplicates. Also giving full control over Elements that needs to be duplicated.
Duplicate Page
Our next plugin on the list is Duplicate Page by Mdp Singh. If you want a simple way to duplicate posts and not dig settings for customizations, this is the plugin you are looking for.
Final Verdict
Final Thoughts
We hope this article gave you a enough information about different ways to duplicate a post, page or custom post types.
By far, using a plugin is the cleanest way to create a duplicate. But other methods are also equally useful in specific scenarios.