How to Duplicate WordPress Page or Post With and Without Plugins
Sometimes we want to take a backup of our currently working on WordPress post or page. And it’s a good habit when you are working on a really important project. Duplicate WordPress page or post with a single click can save you lots of effort and time.
Duplicate post or page allows you to take a backup of your existing work as a template, which you can use for future preferences. In this article, we will explain to you how to duplicate a WordPress page or post with and without plugins.
There are lots of ways to do clone a post or page in WordPress. We will cover all of them. Without any wasting time, let’s jump into it.
How To Duplicate Page or Post with WordPress Plugin
The easiest way to duplicate a WordPress page or post by using a plugin. There are lots of free plugins available at the WordPress plugin library. You just need to install and activate the plugin. After activation duplicating a page or post is a 1-click away.
Let’s take a look at which plugins can make this job easier for you. We will discuss the best WordPress plugin to duplicate posts or pages as well as how to use them shortly.
1. Duplicate Page Plugin
Duplicate page WordPress plugin is the best plugin we have ever used. You can duplicate WordPress page, post and custom post with a single click and it will save as your preferred options (draft, pending, private or public).
Duplicate Page Pro edition gives you more freedom like:
- User Roles: You can give users permission to access Duplicate Page.
- Clone Link Location: You can choose where to show the clone link.
- Post Types: Filter to show Duplicate Page link in post types.
- Status: Option to select Duplicate Posts Status.
- Redirection: Option to Redirect after a click on the clone link.
- Clone Link Title: Option to change Duplicate Post Link Title.
- Post Prefix: Option to add Post Prefix.
- Post Suffix: Option to add Post Suffix.
- Editor: And a lot more features.
To clone your WordPress posts or pages using Duplicate Page plugin, follow these simple steps:
- First, install and activate the plugin.
- After activation select the duplicate page settings menu from the settings tab and do your desired changes.
- Now go to your WordPress dashboard then click on Post -> All Post (if you’re going to duplicate a post) or Pages -> All Pages (if you want to duplicate a page).
- If you hover over the post or page which you want to clone, you will see a new option ‘Duplicate This‘.
- Click ‘duplicate this’ button and you are done. You will see a new draft that can be opened using the post/page editor.
2. Duplicate Post Plugin
The powerful Duplicate post WordPress plugin allows you to duplicate not only content (post and pages), it also duplicates comments, menu orders, slugs, etc for future use.
Like duplicate page pro plugin, it allows you almost all freedoms. You can add prefix or suffix to the post and pages. So it became easier for you to remember which is a clone and which is original.
For example, you want to set ‘Clone Of’ as the title prefix for each clone post/page. Now if you duplicate a post named ‘What is SEO?’, the clone will be named “Clone of What is SEO?”.
To duplicate WordPress page or post using Duplicate Post plugin, follow these simple steps:
- Install and activate the duplicate post plugin.
- Go to ‘Edit Posts’/’Edit Pages’, then you can click on the ‘Clone’ link below the post/page title. This will automatically create a copy and save it as a draft.
- In the post edit screen, you can click on ‘Copy to a new draft’ above ‘cancel’/’Move to trash’.
For more help, you can refer to its documentation site: Duplicate post plugin documentation.
3. Post Duplicator WordPress Plugin
Post Duplicator plugin allows you to create an exact copy of posts or pages while it retains all custom taxonomies and custom fields as well. Custom post types are also supported.
Let’s check how to duplicate a WordPress page or post using Post Duplicator plugin:
- As always install and activate the plugin.
- Now hover over the post or the page you want to clone, and select ‘Duplicate {post_type}’ (Duplicate Post or Duplicate Page) to create a duplicate post.
- That’s it.
You can customize the plugin settings if you wish. Go to Tools > Post Duplicator and set the post status (draft, same as the original or published), post date and post type.
How To Duplicate WordPress Page or Post Without Plugins
Apart from using regular WordPress plugins, you also have a choice to make some tweak on coding to duplicate posts or pages. Coding geeks will love this method.
You just need to put the below code snippet to your functions.php file. Login to your Cpanel file manager, FTP or you can do it via inbuilt WordPress file manager.
Code snippet for duplicate WordPress post
/*
* 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 );
Code snippet for duplicate WordPress post
This above code snippet only works for duplicating WordPress posts. You can duplicate WordPress pages by changing the last line with this code:
add_filter('page_row_actions', 'rd_duplicate_post_link', 10, 2);
Don’t have access to FTP or Cpanel? Don’t worry. Navigate to Appearance > Theme Editor, and select Theme Functions.
Now, if you have successfully added the code to your functions.php file, you should see a Duplicate button in All Posts or All Pages.
Conclusion
We hope in this tutorials we have covered up all tips & tricks on how to duplicate WordPress page or post with or without plugins. Let’s recap the summary:
With Plugins: You can duplicate or clone WordPress posts or pages easily. For this, you have so many plugins available like Duplicate Page, Duplicate Post or Post Duplicator plugin.
Without Plugins: If you are an expert at coding then you can try this. Just edit the function.php file with the above code and done.
Do you know any other way to do that? Share in the comment section so everybody can use that method too. Anyway if you have any questions you can ask at comment or contact us. Meanwhile, you can check out other tutorials.