Often when you want to create a similar form of page or post, duplicating can be an easy way to do that. But in WordPress, there’s no way you can do that by default. Without the clone alternative, you will need to create the same page or post from the start while retaining the format and style. And this process can take a lot of time and effort.
Luckily, we’re using WordPress, which is one of the most versatile platforms. Here you get some easy options that can help you clone pages or posts. You can make error-free improvements to it simply by duplicating the contents.
In this post, we’ll discuss more of these simple steps to replicate your pages or posts. You can duplicate your page or post by using WordPress plugins or manually.
How to duplicate a Page or Post in WordPress using Plugins
There are many free plugins available that can help you duplicate posts and pages within a few clicks. Some of these plugins are
Post Duplicator
Post Duplicator is one of the simplest plugins that let you create an exact duplicate of the selected page or post. It’s got over 100 K active installs.
You can simply install and activate this plugin and see the Duplicate option in your pages or posts section. After clicking the Duplicate Page or Post option, it will clone the selected content type while retaining custom fields and custom taxonomies as well. Except for the comments.
If you want to make any changes with the plugin. Goto Tools >> Post Duplicator and you can set the post status (drafts, published, or same as original, pending), post types, duplicate title and slug from the original content.
Duplicate Post
Duplicate Post is a popular WordPress plugin that offers more than just duplicating content. It has over 3 million active installs.
With this plugin you can copy the title, slug, comments, status, featured images, format and more. Also, you can add title prefix and suffix to the duplicated content.
It’s also very easy to set up this plugin. Simply install and activate it. You can enable and disable options of this plugin from the settings menu.
It allows both pages and posts to be cloned. Also, it gives you the option to choose the New Draft to create a cloned version of the chosen post and open it in the post editor.
Duplicate Page and Post
Duplicate Page and Post is another quick plugin for duplicating posts and pages. it has over 50,000 active installs.
You can simply install and activate this plugin and it will start its job. However, you can customize a few options like post status, suffix, etc. in the Settings of this plugin.
When you clone a post or page, it will appear as a new draft with the same name as the original one. Then you can open and edit the content.
Duplicate Page
Duplicate Page is another popular plugin with more than 1 million active installs. This comes with free and paid versions of it. The free version comes with fewer features than any other free plugins on the list.
Installing and activating this plugin is similar to any other plugins in the lists. You can customize the post status, suffix and some more in the settings menu of the plugin.
How to duplicate a Page or Post in WordPress without Plugins
Copying the Content Manually
This method is very simple and can be done quickly but can be done for only one page or post at a time.
All you have to do is, open the post or page you want to copy.
After that click on the 3 dot menu on the top right of that post or page.
Choose the Copy All Content to draw content from that page or post.
Then add a new page or post, and paste the copied content.
After that make adjustments with the new page or post to make it different from the older post.
This way, you can create an exact page or post, but it may take some time, also, this process may confuse users with the same type of content.
Tweaking Codes
There are plenty of other plugins and methods for duplicating the page or post. But this one is pretty simple, clean and fast to do. You don’t have to rely on any other plugins if you implement this.
But please keep a backup of your website before proceeding and editing the key elements.
Now, let’s start, first copy the following code snippet:
/*
* 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 );
The above code works for duplicating posts, but if you want to duplicate pages, replace the last line of the above code with following:
add_filter('page_row_actions', 'rd_duplicate_post_link', 10, 2);
After copying the code you need to go to Appearance >> Theme Editor select Theme Functions and paste the code here.
After successfully implementing the code you will see in the posts or pages like this:
Conclusion
I hope this blog post will answer all your questions regarding duplicating post or WordPress page. You can use plugins or manual options to do that.
If you have any doubts, please let me know in the comment section below.
Subscribe to our YouTube channel for videos related to WordPress plugins and themes. Follow us on Facebook and Twitter for updates related to WordPress.
You may also like:
Leave A Comment